While blazor signal/r datagram tracing is difficult, you could use the browser tools to see any messages are appearing.
Issue in Blazor: File Upload with Zero Byte Size
Hello,
I'm facing an issue with my Blazor application when attempting to upload a file. Sometimes the file uploads correctly, but other times the file is uploaded with a size of zero bytes.
The issue does not always occur, making it difficult to pinpoint the root cause.
Here is a simplified version of the code I am using:
<div class="mb-3">
<InputFile OnChange="HandleFileSelected" />
</div>
private async Task HandleFileSelected(InputFileChangeEventArgs e)
{
var uploadPath = Path.Combine(env.WebRootPath, "Upload");
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
var file = e.File;
if (file != null && file.Size > 0)
{
var filePath = Path.Combine(uploadPath, file.Name);
using (var stream = new FileStream(filePath, FileMode.Create))
{
await file.OpenReadStream(maxAllowedSize: 200 * 1024 * 1024).CopyToAsync(stream);
}
}
}
Are there any known reasons why this issue might be happening in Blazor? Could there be a problem with the project configuration or environment? Any help would be greatly appreciated.
Thank you in advance!
2 answers
Sort by: Most helpful
-
-
AgaveJoe 28,536 Reputation points
2024-08-03T09:42:40.78+00:00 It seems that large files are uploaded to Plesk with a size of 0 bytes until the upload is complete. I was clicking a button that interacts with the uploaded file before the upload is finished, Is there a way to check if the upload is complete or to wait until the upload is finished?
The official documentation has code examples for canceling a file upload and implementing file upload progress.