Hello :)
I'm currently attemping to build a uploader to upload large (10GB+) files to blob storage.
Currently if my connection to blob storage fails I hit the OnFailure event. But the uploader keeps trying to upload.
How can I get a bad blob connection to trigger the uploader to pause its uploading process?
below is how I have my sfUploader and SaveUrl set up
<SfUploader ID="UploadFiles" AutoUpload=false MaxFileSize="50485760000" AllowMultiple=false>
<UploaderAsyncSettings SaveUrl="api/FileUpload/Save" ChunkSize="10000000"></UploaderAsyncSettings>
<UploaderEvents Paused="@OnPaused" OnResume="@OnResume" OnCancel="@OnCancel" OnFailure="@OnFailure" OnChunkFailure="OnFailure" OnChunkSuccess="OnChunkSuccess"></UploaderEvents>
</SfUploader>
[HttpPost("Save")]
public async Task Save(IList<IFormFile> chunkFile, IList<IFormFile> UploadFiles)
{
try
{
var test = HttpContext.Request.Form.Files["chunkFile"];
var chunkIndex = HttpContext.Request.Form["chunk-index"];
var totalChunk = HttpContext.Request.Form["total-chunk"];
var chunkMetadata = HttpContext.Request.Form["ChunkMetaData"];
if(chunkFile.Count > 0) //if we chunk upload
{
foreach(var file in chunkFile)
{
var filename = $"Appended - {file.FileName}";
using Stream uploadStream = new MemoryStream();
file.CopyTo(uploadStream);
uploadStream.Flush();
uploadStream.Position = 0;
// how to catch exception from blob?? AND pause uploading
await blobService.UploadFileToBlobAsync(uploadStream, filename);
}
}
else // if we are uploading a file lower in size than chunk size it comes through the UploadFiles list
{
foreach(var file in UploadFiles)
{
var filename = $"{file.FileName}";
using Stream uploadStream = new MemoryStream();
file.CopyTo(uploadStream);
uploadStream.Flush();
uploadStream.Position = 0;
// this may need a different handling of how we upload to blob?
await blobService.UploadFileToBlobAsync(uploadStream, filename);
}
}
}
catch(Exception e)
{
Response.Clear();
Response.StatusCode = 400;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File failed to upload";
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message;
Response.Headers.Add("ID", "Maximum Uploaded files reached");
}
}