1 | initial version |
You can implement a server side progress function while uploading a file to the client in ASP.NET Core 7 Web API controller using the following steps:
public async Task<iactionresult> UploadFile(IFormFile file)
var totalBytes = file.Length; var uploadedBytes = 0L;
...
if (chunkedFile.Length > 0) { await fileStream.WriteAsync(chunkedFile, cancellationToken); uploadedBytes += chunkedFile.Length;
// Calculate progress percentage
var progress = Convert.ToInt32((uploadedBytes * 100) / totalBytes);
}
return Ok(progress);