Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Problem converting Image to Base64 in Blazor Server

$
0
0

So I am trying to convert an image base64 that will be uploaded to SQL Server.

Current code is:

private async Task OnInputFileChange(InputFileChangeEventArgs args){    var maxFiles = 1;    var maxSize = 512000000;    var format = "image/jpg";    test = "Something";    test1 = args.FileCount.ToString();    foreach (var file in args.GetMultipleFiles(maxFiles))    {        var image = await file.RequestImageFileAsync(format, 500, 500);        test = image.Size.ToString();        buffer = new byte[image.Size];        await image.OpenReadStream(maxAllowedSize: maxSize).ReadAsync(buffer);        test1 = buffer.ToString();        var imageDataUrl = $"data:{format};base64,{Convert.ToBase64String(buffer)}";        imageDataUrls.Add(imageDataUrl);        imageString = imageDataUrl;    }}

It begins fine, however only the top portion of image is actually converted and in the string is followed by thousands of repeating "A". Reconstructing the image just shows the top portion of the image. What am I doing wrong?

Currently I had not uploaded and redownloaded the string, it is all local until I can figure out what is wrong. I am using the imageString for the image source. I am using .net 6.0.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>