79743463

Date: 2025-08-22 13:48:41
Score: 1
Natty:
Report link

The "AAAA..." pattern indicates you're getting null bytes in your buffer. The issue is that ReadAsync(buffer) doesn't guarantee reading the entire stream in one call.

Use CopyToAsync() with a MemoryStream instead:

using var stream = file.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024);
using var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);
var base64String = Convert.ToBase64String(memoryStream.ToArray());

For a complete solution with security considerations, check out this guide: How to Convert an Image to a Base64 String in Blazor

Reasons:
  • Blacklisted phrase (1): this guide
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Udhaya Kumar