Js interop function can receive byte[] from dotnet as parameter.
Vice versa is not working, I can't call dotnet function passing arraybuffer (Uint8Array) as parameter and receive byte[] in dotnet, giving error.
I am forced to do extra job, in js convert received binary to base64string and pass to dotnet function, then convert back it to byte array.
Is it possible to get binary data from js?
I figured this out here after advise from gitter to follow links below, but it was hard and suffering.
Can we make this simpler somehow?
https://github.com/aspnet/AspNetCore/blob/master/src/Components/Browser.JS/src/Services/Http.ts#L46
@SteveSandersonMS any recommendations here? Thanks
From the links you posted, it looks like you've figured out how to use the unmarshalled interop APIs to transfer the binary data directly.
We don't expect to add support for binary serialization into the marshalled interop APIs, because they use JSON as a transfer format (because developers understand well what that means for .NET/JS conversions), and JSON itself doesn't have a binary blob primitive.
If we get more requests to simplify this in the unmarshalled case we could consider it, but for now this looks like a pretty rare requirement so it's not likely we'd want to build in a feature for it. Anybody could create a simplified API for this and ship it in a NuGet package, so that would be the best way forwards for now.
im using blazor jsinterop to pass ArrayUint8 to byte[] but it gives me json error :(
Hi.
It looks like you are posting on a closed issue!
We're very likely to lose track of your bug/feedback/question unless you:
Hi.
It looks like you are posting on a closed issue!
We're very likely to lose track of your bug/feedback/question unless you:
- Open a new issue
- Explain very clearly what you need help with
- If you think you have found a bug, include detailed repro steps so that we can investigate the problem
thanks!
One easy workaround when dealing with Blobs is to create a URL in the browser for the Blob and then in Blazor use the standard HttpClient to get the binary by data calling GetByteArrayAsync pointing to the created blob URL (as suggested by this SO answer).