I'm trying to send image from Blazor to JS with a WebSocket, I don't know the way. I'm trying to send a base64 or byte[] but Base64string if I upload really big images use all the memory and it collapse and the app stop working. I'm trying to send a byte[] but I'm not sure how to make that, and next I have to download the image on the server. So I need to convert that byte[] to an image.
There is how I transform the file to a byte[]:
public async Task<byte[]> GetByteArrayFromFile(IBrowserFile imageFile)
{
var resizedImage = await imageFile.RequestImageFileAsync("image/jpg", 40000, 20000);
Stream jsImageStrea = resizedImage.OpenReadStream(1073741824);
MemoryStream ms = new MemoryStream();
await jsImageStrea.CopyToAsync(ms);
return ms.ToArray();
}
I'm using this to transform byte[] to base64
Convert.ToBase64String(byte[])
If someone can help I would appreciate it, thanks.