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
HttpClient enhancements - binary data #16257
Comments
Thanks @SvenEV - it's good to have an issue to track this. So, starting a list of possible future enhancements:
|
Also byte arrays. I ran into this last night, and changed my code to base64 encode the data, but it would be more efficient to just pass the binary byte array like on other platforms. |
Upload/Download progression events |
And consuming Content-Type: application/msbin1 web services would be helpful for large data transfer apps. |
Don't know if it's in the scope of this issue |
#815) * Add support for zero copy byte array marshalling * Add support for sending arbitrary HttpContent, refs #479 * Fix unit test to set ContentType correctly * Add support for receiving binary data * Compare header case insensitive * Add unit test for binary http requests
@rockfordlhotka |
dotnet#815) * Add support for zero copy byte array marshalling * Add support for sending arbitrary HttpContent, refs #479 * Fix unit test to set ContentType correctly * Add support for receiving binary data * Compare header case insensitive * Add unit test for binary http requests
Hello, I would just like to ask if someone could provide an example on how to use this feature to upload files from the client and send it to the server? I'm completely new to web development so any help would be greatly appreciated. Thanks! On client-side I have
On server-side, I think it's something like this
|
@gojanpaolo https://remibou.github.io/Upload-file-with-Blazor/ |
@smartprogrammer93 yes I found that. But it needs JS Interop. I thought this merged PR solved not having to use JS Interop during file upload? giving it a try..
Index.razor
UploadController.cs
|
@gojanpolo No need for steing builder. The code you see is a bit outdated. The response you will get is probably a string so T should be a string. I am not sure if you can use byte array instead |
@smartprogrammer93 Please see updated https://github.com/aspnet/Blazor/issues/479#issuecomment-498920109. I tried to follow the blog as best I can but it still doesn't seem to work. |
I read the code again. And in this case, T should be a string builder. But i am pretty sure if you change the js code to return the content right away instead of a data object with a content property inside it, it could work with steing |
@gojanpaolo If you're still hitting problems with using HttpClient to send/receive binary data in Blazor please open a new issue in the https://github.com/aspnet/aspnetcore repo with the steps and code needed to reproduce the issue and we'll take a look. |
@smartprogrammer93 thanks for the suggestions, I tried using StringBuilder instead but doesn't work too. Not sure how to change the js code, it's too foreign for me. @danroth27 Thank you for responding. I think the issue I'm having is more on how to get file uploading work in client-side blazor. As commented above, it looks like I need to use JSInterop, but I have no experience in javascript. I was hoping there's a way to do it in C#. |
Currently
HttpClient
cannot be used to retrieve binary data such as images. The response content appears to get truncated at zero bytes when the HTTP response is returned from JS back to .NET. In some cases, requests just fails with "SCRIPT7017: Memory index is out of range" (Edge) or "RuntimeError: memory access out of bounds" (Chrome) without anything being returned.I found a TODO regarding this issue in the code (see below). Anyway, I think this should be tracked and I hope this isn't a duplicate.
https://github.com/aspnet/Blazor/blob/a9c45fe78ac18b6bd524904b40896c249f9f09c0/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Services/Http.ts#L32-L47
The text was updated successfully, but these errors were encountered: