tewr / blazorfilereader Goto Github PK
View Code? Open in Web Editor NEWLibrary for creating read-only file streams from file input elements or drop targets in Blazor.
License: MIT License
Library for creating read-only file streams from file input elements or drop targets in Blazor.
License: MIT License
Up until preview6, the blazor filereader Wasm library used unmarshalled calls to communicate the file chunks from js to .net. This is no longer the case due to a breaking change in blazor(mono?) that broke the implementation. Might be something as simple as a name change in the API, have not investigated thoroughly.
Main motivation of reintroducing this thing is speed (~30% faster) and general memory / cpu usage (not really benchmarked though current marshaled memory usage should at minimum the be 2.4 * buffer size compared to unmarshalled)
First issue is how to re-implement the method.
The original implementation passed a reference to a byte array to js in the first call. Current implementations doing about the same thing (ex http message handler in blazor) rather have a call originating from js to allocate and get a reference to that array, which could be considered being the reference implementation.
Second issue, how to enable usage of the method..
As there is still no WASM target for libraries, an initialization option has to be added that enables referencing MonoWebAssemblyJSRuntime.InvokeUnmarshalled<...>
. I'm a little bit unhappy about making end-users do that this as it makes setup quite complex. Might be possible with a simple boolean option but that would cost a lot in reflection instead.
The build experience should be improved, as theres a few manual steps involved with the current state of things
A gulp script could be used to achieve this.
This is almost certainly not an actual bug, and instead will likely just illustrate my lack of understanding of streams in .Net. I'm trying to use the azure SDK to stream file contents to blob storage without loading it all into memory first. The azure SDK has the following signature:
public class BlobClient : BlobBaseClient{
Task<Response<BlobContentInfo>> UploadAsync(Stream content);`
}
So the idea here is you can just give it a stream, and it will upload it for you. So perhaps something like this:
using (Stream stream = await file.OpenReadAsync()) {
await blobClient.UploadAsync(stream);
}
However this fails due to the restriction to async-only reads and a NotSupportedException
is raised in FileReaderJsInterop
as the azure blob client attempts to call Read
on the underlying stream.
Read
when running on the server side?Also just wanted to extend a warm thank you for the work on this package, it's a lot of work creating a great file upload experience and this package takes care of so much heavy lifting!
Hi there.
I'm using this library to upload relatively small images on client side Blazor. After updating to prev 9 at compile time I get
Unhandled Exception: Mono.Linker.MarkException: Error processing method: 'System.Void Blazored.Typeahead.BlazoredTypeaheadBase
1/d__63::MoveNext()' in assembly: 'Blazored.Typeahead.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Threading.Tasks.Task1<!!0> Microsoft.JSInterop.IJSRuntime::InvokeAsync(System.String,System.Object[])
this error.
(In prev. 8 everything worked fine)
Please let me know if you have encountered something similar or know where to look for a solution.
Thank you
The full error message:
Processing embedded resource linker descriptor: System.Text.Json.xml
Processing embedded resource linker descriptor: System.Text.Encodings.Web.xml
Processing embedded resource linker descriptor: mscorlib.xml
Duplicate preserve in resource mscorlib.xml in mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e of System.Threading.WasmRuntime (All). Duplicate uses (All)
Duplicate preserve in resource System.Text.Encodings.Web.xml in System.Text.Encodings.Web, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Text.Encodings.Web.TextEncoder (Nothing). Duplicate uses (Nothing)
Duplicate preserve in resource System.Text.Encodings.Web.xml in System.Text.Encodings.Web, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Buffers.OperationStatus System.Text.Encodings.Web.TextEncoder::EncodeUtf8Shim(System.Text.Encodings.Web.TextEncoder,System.ReadOnlySpan1<System.Byte>,System.Span
1<System.Byte>,System.Int32&,System.Int32&,System.Boolean)
Duplicate preserve in resource System.Text.Encodings.Web.xml in System.Text.Encodings.Web, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Int32 System.Text.Encodings.Web.TextEncoder::FindFirstCharacterToEncodeUtf8Shim(System.Text.Encodings.Web.TextEncoder,System.ReadOnlySpan1<System.Byte>) Duplicate preserve in resource System.Text.Json.xml in System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Text.Json.JsonPropertyInfoNullable
2 (Nothing). Duplicate uses (Nothing)
Duplicate preserve in resource System.Text.Json.xml in System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Void System.Text.Json.JsonPropertyInfoNullable2::.ctor() Duplicate preserve in resource System.Text.Json.xml in System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Text.Json.Serialization.JsonPropertyInfoNotNullableContravariant
4 (Nothing). Duplicate uses (Nothing)
Duplicate preserve in resource System.Text.Json.xml in System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Void System.Text.Json.Serialization.JsonPropertyInfoNotNullableContravariant4::.ctor() Duplicate preserve in resource System.Text.Json.xml in System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Text.Json.Serialization.Converters.JsonConverterEnum
1 (Nothing). Duplicate uses (Nothing)
Duplicate preserve in resource System.Text.Json.xml in System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Void System.Text.Json.Serialization.Converters.JsonConverterEnum1::.ctor(System.Text.Json.Serialization.Converters.EnumConverterOptions) Duplicate preserve in resource System.Text.Json.xml in System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Void System.Text.Json.Serialization.Converters.JsonConverterEnum
1::.ctor(System.Text.Json.Serialization.Converters.EnumConverterOptions,System.Text.Json.JsonNamingPolicy)
Duplicate preserve in resource System.Text.Json.xml in System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Text.Json.Serialization.Converters.JsonKeyValuePairConverter2 (Nothing). Duplicate uses (Nothing) Duplicate preserve in resource System.Text.Json.xml in System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 of System.Void System.Text.Json.Serialization.Converters.JsonKeyValuePairConverter
2::.ctor()
Type System.Reflection.Assembly has no fields to preserve
Type Mono.ValueTuple has no fields to preserve
Fatal error in IL Linker
Unhandled Exception: Mono.Linker.MarkException: Error processing method: 'System.Void Blazored.Typeahead.BlazoredTypeaheadBase1/<HandleFocus>d__63::MoveNext()' in assembly: 'Blazored.Typeahead.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Threading.Tasks.Task
1<!!0> Microsoft.JSInterop.IJSRuntime::InvokeAsync(System.String,System.Object[])
at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue()
--- End of inner exception stack trace ---
at Mono.Linker.Steps.MarkStep.ProcessQueue()
at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
at Mono.Linker.Steps.MarkStep.Process()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
at Mono.Linker.Pipeline.Process(LinkContext context)
at Mono.Linker.Driver.Run(ILogger customLogger)
at Mono.Linker.Driver.Execute(String[] args, ILogger customLogger)
at Mono.Linker.Driver.Main(String[] args)
Server-side Blazor is not working fully on Microsoft Edge.
What exactly is not working needs some further investigation. Looks like the read callback. Might be related to #24 .
Is there any way to improve the memory usage when you need all the bytes into memory? I loaded all the bytes into memory using the "CreateMemoryStreamAsync" and then doing a .ToArray() to convert the bytes into a Base64, so that I can upload this string up to my S3 Bucket.
However, even tho it does work, these are the horrific stats:
An image with the size of 5 MB, increased the memory usage of the application by 50 MB.
This happens everytime you select an image, it keeps increasing it (ofcourse with different stats than 50 MB, depending on the file size). I even tried setting the string to the "SecureString" so it could be disposable, but even that didn't clear the memory afterwards.
So simply, any way to improve the memory usage, or clear the memory usage after not needing it anymore?
Describe the bug
Uploading a file > 30MB results in
Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer: Error: Unexpected exception in "IISHttpContext.ReadBody".
Microsoft.AspNetCore.Server.IIS.BadHttpRequestException: Request body too large.
at Microsoft.AspNetCore.Server.IIS.BadHttpRequestException.Throw(RequestRejectionReason reason)
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadBody()
(the error actually happens at about 21.3MB of the file transferred).
To Reproduce
Steps to reproduce the behavior:
Project type
Server-side
Environment
Additional context
I've tried increasing the signalr message size, but I don't think that's the issue here. IIS is complaining that the request body is too big.. I'm not sure why it would be. Below is my code:
<input type="file" @ref="inputTypeFileElement" />
<button type="button" @onclick=ReadFile>Read file</button>
@code {
private ElementRef inputTypeFileElement;
public async Task ReadFile()
{
foreach (var file in await fileReaderService.CreateReference(inputTypeFileElement).EnumerateFilesAsync())
{
var buffer = new byte[16384];
int read = 0;
using (Stream stream = await file.OpenReadAsync())
{
using (var fileStream = new FileStream("incomingFile.bin", FileMode.Create, FileAccess.Write))
{
while ((read = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await fileStream.WriteAsync(buffer, 0, read);
}
}
}
}
}
}
Can i write data directly to IFileReference? I want to resize image in browser, save data and then send data to API controller.
Something like this:
using (var stream = await file.CreateMemoryStreamAsync())
{
using (Image image = Image.Load(stream))
{
image.Mutate(x => x.Resize(image));
image.SaveAsJpeg(stream);
}
// save back to IFileReference
await stream.WriteAsync(file);
}
I use client-blazor RC1
Hi, I wanted to leave an example of this library being used in a demo of a real world scenario.
I shared this on my Twitch TV Show: Blazor StateHasChanged
https://youtu.be/-IuZQeZ10Uw
The demo source doesn't contain the Excel import page contained in the live demo. Is this because you hit the same issue that I did when referencing EPPlus (and some other packages) where the linker fails because the parameter list is too long?
Since 3.0.0 preview 4, Server-side blazor Json Serialization fails with a not very descriptive exception if the signalR message is too large (over 2895), and when set lower, sporadically:
after this function call:
which calls
we get this:
Uncaught (in promise) Error: System.Runtime.Serialization.SerializationException: Invalid JSON string
at SimpleJson.SimpleJson.DeserializeObject(String json)
at SimpleJson.SimpleJson.DeserializeObject(String json, Type type, IJsonSerializerStrategy jsonSerializerStrategy)
at SimpleJson.SimpleJson.DeserializeObject[T](String json)
at Microsoft.JSInterop.DotNetDispatcher.InvokeSynchronously(String assemblyName, String methodIdentifier, Object targetInstance, String argsJson)
at Microsoft.JSInterop.DotNetDispatcher.BeginInvoke(String callId, String assemblyName, String methodIdentifier, Int64 dotNetObjectId, String argsJson)
at endInvokeDotNetFromJS (blazor.server.js:8)
at blazor.server.js:8
at new Promise (<anonymous>)
at e.beginInvokeJSFromDotNet (blazor.server.js:8)
at blazor.server.js:1
at Array.forEach (<anonymous>)
at e.invokeClientMethod (blazor.server.js:1)
at e.processIncomingData (blazor.server.js:1)
at e.connection.onreceive (blazor.server.js:1)
at WebSocket.i.onmessage (blazor.server.js:1)
endInvokeDotNetFromJS @ blazor.server.js:8
(anonymous) @ blazor.server.js:8
beginInvokeJSFromDotNet @ blazor.server.js:8
(anonymous) @ blazor.server.js:1
e.invokeClientMethod @ blazor.server.js:1
e.processIncomingData @ blazor.server.js:1
connection.onreceive @ blazor.server.js:1
i.onmessage @ blazor.server.js:1
Not really clear if this is happening on the server or on the client, but I suspect the client as the task on the server never resolves.
Seems that with an even lower buffer size, like 2000, it never happens.
Anything over 3000, it happens all the time. Fun stuff!
you have
<th @rowspan="cell.Rowspan" @colspan="cell.Colspan">@cell.Value</th>
should be
<th rowspan="@cell.Rowspan" colspan="@cell.Colspan">@cell.Value</th>
Also the code will link fine for the server side demo.
Describe the bug
Building an blazor app server-side with FileReader works without any problem. When deploying as docker container, startup fails as it wants to access "/root/.nuget/packages/tewr.blazor.filereader/0.15.0.19248/staticwebassets" during first run, which is not mounted as a volume.
Error message
Unhandled exception. System.IO.DirectoryNotFoundException: /root/.nuget/packages/tewr.blazor.filereader/0.15.0.19248/staticwebassets/
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
at Microsoft.AspNetCore.Hosting.StaticWebAssets.StaticWebAssetsFileProvider..ctor(String pathPrefix, String contentRoot)
at Microsoft.AspNetCore.Hosting.StaticWebAssets.StaticWebAssetsLoader.<>c.<UseStaticWebAssetsCore>b__2_0(ContentRootMapping cr)
at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.OfTypeIterator[TResult](IEnumerable source)+MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Microsoft.AspNetCore.Hosting.StaticWebAssets.StaticWebAssetsLoader.UseStaticWebAssetsCore(IWebHostEnvironment environment, Stream manifest)
at Microsoft.AspNetCore.Hosting.StaticWebAssets.StaticWebAssetsLoader.UseStaticWebAssets(IWebHostEnvironment environment, IConfiguration configuration)
at Microsoft.AspNetCore.WebHost.<>c.<ConfigureWebDefaults>b__9_0(WebHostBuilderContext ctx, IConfigurationBuilder cb)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass8_0.<ConfigureAppConfiguration>b__0(HostBuilderContext context, IConfigurationBuilder builder)
at Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
Project type
Server-side
Environment
What might be a solution to avoid this error and to avoid mounting as a volume as this is not available on client environments? Should I include the static assets directly in the source folder?
WASM Setup currently requires some clunky copy-paste implementation of an obscure plumbing interface. Could be fixed by providing another micro-nuget-package.
Some of the recent framework issues have shown that the error management could be improved.
I got an error when run it in server side blazor.
[System.PlatformNotSupportedException] Requires MonoWebAssemblyJSRuntime as the JSRuntime
Blazor.registerFunction() is no longer needed, because the new IJSRuntime.InvokeAsync() invokes the (specified) method on the current window-object.
Describe the bug
When calling ReadFileInfoAsync using Server Side Blazor Preview 8. You get "An exception occurred executing JS interop: The JSON value could not be converted to Blazor.FileReader.FileInfo. Path: $ | LineNumber: 0 | BytePositionInLine: 104.. See InnerException for more details."
Seems like JS is pulling info, but server.blazor.js errors.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
It returns fileinfo
Screenshots
Project type
Server-side
Environment
Additional context
Stacktrace
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.JSInterop.JSRuntimeBase.<InvokeWithDefaultCancellation>d__13
1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Blazor.FileReader.FileReaderJsInterop.<GetFileInfoFromElement>d__15.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
at Blazor.FileReader.FileReference.d__8.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at VisualBlazor.Pages.Qutes.View.d__96.MoveNext() in E:\VisualApprovals\VAPortal3\Pages\Qutes\View.razor:line 948
I suppose, this is the build where initial debugging support has been implemented.
Error is WASM: [Microsoft.JSInterop.JSException] Blazor.platform is undefined
Hi,
I'd like to fake the popular "dropzone.js" with BlazorFileReader.
Main motivation is, that dropzone.js can collect multiple drag+drops and start the upload afterwards.
Unfortunately, BlazorFileReader's DragDrop-Demo clears the droplist before every dropevent-handling. I'm a simple man, so I removed FileList.Clear() in RefreshFileList()) ;-) - was fine on the first look.
But on the second, I realized that the FileInfo-Contents changed but IFileReference.ReadFileInfoAsync() returned the same stream twice. :-(
What has to be done to mimic "dropzone.js"'s behavior?
Thanks for help!
Sascha
Describe the bug
When i try to read a csv file of 40.000kb (360.000 lines) i takes a really long time (couple minutes)
im using:
new StreamReader(await _fileReference.OpenReadAsync()
I tried reading by line:
var line = await reader.ReadLineAsync();
or reading by file
var text = await reader.ReadToEndAsync();
This took 4.03 minutes for 40927219 chars.
My computers does start using more memory but nothing extreme.
As discussed in #35 . This could be a useful method to have while still having a slim API. This method should be on IFileReaderRef
. IMO a better API than to use bind
, also considering that bind currently crashes in Ms Edge
Currently (since 0.8.0 in server-side, for both projec types in 0.9.0), the js interop file must be added manually on the index page.
Apparently static content serving from blazorlib is a feature that no longer exists - "a known limitation with the Razor Components template in Preview 2" . This bug is what I'm experiencing, and like it says it's being tracked in issue dotnet/aspnetcore/issues/6349 .
Unhandled exception rendering component: Could not find 'FileReaderComponent' in 'window'.
Error: Could not find 'FileReaderComponent' in 'window'.
The error occurs on: RegisterDropEventsAsync();
:
protected override async Task OnAfterRenderAsync()
{
labelFilesReference = fileReaderService.CreateReference(labelElement);
await labelFilesReference.RegisterDropEventsAsync();
}
I do have InitializeOnFirstCall
enabled, but I also tried this as well:
protected override async Task OnAfterRenderAsync()
{
await fileReaderService.EnsureInitializedAsync();
labelFilesReference = fileReaderService.CreateReference(labelElement);
await labelFilesReference.RegisterDropEventsAsync();
}
... and still received the error (same frequency). Adding Task.Delay did not help.
Retrying when it fails fixes the issue, which I think is probably evidence that there is a race condition here (which could mean the problem can only be replicated at very low latency e.g. local development).
This works:
protected override async Task OnAfterRenderAsync()
{
labelFilesReference = fileReaderService.CreateReference(labelElement);
try
{
await labelFilesReference.RegisterDropEventsAsync();
}
catch (JSException ex)
when (ex.Message.Contains("Could not find 'FileReaderComponent' in 'window'"))
{
// failed race condition, just try again
await labelFilesReference.RegisterDropEventsAsync();
}
}
Not a bug - a request. Can we have notification of progress during the upload?
I have code like this:
try
{
using (var stream = await file.CreateMemoryStreamAsync(4096))
{
if (Workbook != null)
{
Workbook.Dispose();
}
Workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
....
}
}
catch (Exception ex)
{
Output += ex.Message;
}
If would useful for larger file to be notified of progress. Maybe an event on IFileReference or a callback in CreateMemoryStreamAsync.
Hi
I am new to html
I use this file picker and it works good but i need some way to reset/clear it.
I have global save button where i save difrent propertys on a object where i also save the file to azureblob. the problem is that the control keep the file refrens så on very save i add a new version of the same file to the azureblob storage.
Some basic end to end tests as in blazor would save a bunch of time as debugging is a pain.
Ideas that could fix the build
A lower-level api should be created, which exposes the base64-encoded string returned by the FileReader.
The use-case is when the byte-stream once the data has arrived to clr-land is just raw data passed on to something else that requires base64-encoding, such as a cloud service.
Current process is either a) file -> byte[] -> base64
(wasm with shared buffer option) or worse b)file -> base64 -> byte[] -> base64
(for server-side or wasm without shared buffer option).
The process should rather be just file -> base64
, the first two steps of process b.
Hi All
Should be a simple referencing fix, but Blazor 0.8.0 has moved the ElementRef to Microsoft.AspNetCore.Components from Microsoft.AspNetCore.Blazor
Try this code but FileReader see only last file
`
<input type="file" multiple @ref=inputElement />
<button @OnClick="Add" class="btn btn-primary">read
<button @OnClick="ReadFile" class="btn btn-primary">read
@code
{
ElementReference inputElement;
IFileReaderRef fileReaderReference;
public async Task AddToList()
{
fileReaderReference = fileReaderService.CreateReference(inputElement);
}
public async Task ReadFile()
{
....
foreach (var file in await fileReaderReference.EnumerateFilesAsync())
{
....
}
}
}
`
https://devblogs.microsoft.com/aspnet/blazor-0-9-0-experimental-release-now-available/
To upgrade a Blazor 0.8.0 project to 0.9.0:
Update the Blazor packages and .NET CLI tool references to 0.9.0-preview3-19154-02.
Update the remaining Microsoft.AspNetCore.* packages to 3.0.0-preview3-19153-02.
Remove any usage of JSRuntime.Current and instead use dependency injection to get the current IJSRuntime instance and pass it through to where it is needed.
@catlan : Thank you for your PR. I'm having trouble firing the drop event using your example. The browser default event is fired (file opens in browser when dropped on element, as if ev.preventDefault() is never called)
Do you have a full example on how to use the code you provided to share?
I tried with preview7.
Regards
Describe the bug
Can't use the file reader component with server side Blazor. The signalr connection fails. On the backend side, the code just hangs when attempting to read from the stream at await stream.ReadAsync
Due to other dependencies with the project, I'm unable to use net 3.0 preview7 at this time.
To Reproduce
Steps to reproduce the behavior:
Pretty much using the suggested code to reproduce this.
public async Task<string> GetImagePathAsync()
{
foreach (var file in await FileService.CreateReference(FileElement).EnumerateFilesAsync())
{
var fileInfo = await file.ReadFileInfoAsync();
using var stream = await file.OpenReadAsync();
var imageData = new byte[stream.Length];
await stream.ReadAsync(imageData, 0, (int)stream.Length);
using var imageStream = new MemoryStream(imageData);
return await Client.UploadImageAsync(imageStream, fileInfo.Name, fileInfo.Type);
}
return null;
}
Project type
Server-side
Environment
Preview 6 added quite a few breaking changes.
Blog: https://devblogs.microsoft.com/aspnet/asp-net-core-and-blazor-updates-in-net-core-3-0-preview-6/
Hi Guys,
I'm a noob in this subject. I have two questions:
Also when loading a .net library in my VS in "Blazor.FileReader.Wasm.Demo", it shows the following error:
[IFileInfo.Name: Blazor.FileReader.dll
IFileInfo.Size: 38912
IFileInfo.Type: application/x-msdownload
IFileInfo.LastModifiedDate: 05/07/2019 04:21:15
Reading file...Done reading file Blazor.FileReader.dll
.Loading assembly...
Assembly loaded.
Loading assembly contents...
Public Types:
Assembly loading of types failed: System.Reflection.ReflectionTypeLoadException: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown.
Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.](url)
Using Visual Studio Preview. All the project settings are as your GitHub, nothing changed.
.Net core version 3.0.0-preview4-19216-03.
Any help is appreciated.
Btw very nice project, good work!
The Drag n Drop API is currently not covered by any E2E test.
This article states that testing it should be quite feasible.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.