-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stream not working as expected #6
Comments
Are you using Blazor Server or Blazor WASM? And yes it uses JS under the hood cause its the only way to trigger browser download but the JS code its embed on a class instead of being reference by the user in the html document. Can you verify that the stream is not empty and the stream Position is 0 before sending the the DownloadFile method? Based on your comment if Try this:
|
Sorry, Blazor server. Should have mentioned that.
|
Try this please and let me know. If this throws an error please paste it over here it may be related to #5 |
It didn't. That one has bit me before so good call. Here is the code that I submitted:
It works fine with stream.ToArray() |
can you send me a sample so I can debug it? As you can see in the internal implementation of stream overload method calls an extension method stream.ToByteArray() and then converts to base64 string internally cause JS runtime doesn't know how to deal with a stream or byte[]. See this issue: dotnet/aspnetcore#21877 |
@AlanChurchill can you check if any error is being thrown in the browser console? |
No error in Console. Yes, I saw that. Very limited time to debug since I have it working (and have my own unrelated bugs in my project). What you may want to consider doing is to not do the tobytearray extension. ToArray works and, from what little I read, it creates the byte array for you. |
@AlanChurchill the stream class doesn't provide a method .ToArray() but since you are using MemoryStream class, this class has the ToArray() method. I may have to consider 2 things use MemoryStream class instead stream class or reimplement the .ToByteArray() extension method. |
How about using the CopyTo depending upon the type of stream:
https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.copyto?view=netcore-3.1
|
Here is the internal implementation of ToByteArray(), not sure if using the CopyTo could be a little overhead
|
Yeah, I looked at it last night. In general, I assume that the internal methods in Core are highly optimized. Minor cost even if a little less efficient. Worth testing or just try and see if it fixes the problem and move on to next issue in coding. Also, this is not something that will be called a lot so should not have to worry too much about it, IMO. |
@AlanChurchill any chance to send a sample which reproduces this error so I can debug it and fix it? |
This seems good. |
I have replicated the basic code but I am not seeing same behavior with this. Hence, it will probably be on my shoulders to find out what is happening. You can see the code in this zip but need the GemBox.Spreadsheet dll (available from their website). |
What you mean by not seeing the same behavior? |
I changed the implementation with the one I shared on the link, also added the overload for bufferSize and tested it on the demo project and seems ok. I am re implementing this library using buffer management to bypass Blazor Server side web socket max size I/O when working with large files. Please follow this issue: #5 I will leave this issue open until you tell me if you had issue from your side or I re implement this and upload a new package version. |
Thanks. What I saw was that the file would be written but was corrupt. When I looked at the binary, it seemed to be written with all null bytes. However, I didn't get too deep into it since I had other things I needed to work on. Once I got it to work with ToArray, off to next problem (you know the game). So, to determine where an issue may lay, I may need to debug source. |
@AlanChurchill in the meantime as it is working with the ToArray method use it like that in the meantime. I will comment back here once I change implementation and re test everything again. Thanks for the report! |
Install-Package BlazorDownloadFile -Version 1.0.12 |
Comments left as to why I do not like that version .... |
@Smurf-IV the method you commented makes sense everything you said but take note that in this version the downloadfile method as overloads, which you can set the desired buffer. The extension method you commented about stream casting to memory stream it's the unbuffered method. For your use of case that extension method won't be used by you. The buffered methods has a total different implementation. Take a look of the current buffered implementantion of stream here
|
First of all, thanks for making this library. I still see a JS dependency in version 1.0.10 that is on nuget.
When I use this code:
It does not work and seems to treat the stream as empty. However, this code does work:
The text was updated successfully, but these errors were encountered: