sfUploader chunk upload used with blob storage. how to pause upload on blob network fail?

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");


     }

 }


1 Reply

UD UdhayaKumar Duraisamy Syncfusion Team April 10, 2024 11:28 AM UTC

You can pause file uploading using the PauseAsync method of the uploader component. 


Check out the documentation for more information: PauseAsync Documentation


This method allows you to pause the uploading process for a specified list of files. It's handy for handling scenarios like network failures during uploads.


Loader.
Up arrow icon