ERR_CONNECTION_RESET when uploading large files on Azure

I'm using Blazor SfUploader Server-Side and I'm having trouble with uploading large files when deployed on Azure.
Locally I don't have any problems so most likely it is a setting/configuration on Azure but I can't find which one.

When uploading I get this error:
syncfusion-blazor.min.js:1 POST https://myWebApp.azurewebsites.net/upload/chunk net::ERR_CONNECTION_RESET

Because I've enabled Chunking and set a high RetryCount the file is eventually uploaded but it takes a long time.

This is my Blazor code:
< SfUploader ID="UploadFiles" AllowedExtensions=".xml" MaxFileSize="429496720" SequentialUpload="true" DropArea="#DropArea">
    < UploaderAsyncSettings SaveUrl="upload/chunk" ChunkSize="25000000" RetryCount="10" RetryAfterDelay="3000">

The controller is the one from https://blazor.syncfusion.com/documentation/file-upload/chunk-upload/ and https://www.syncfusion.com/forums/150303/upload-large-file-to-azure-storage-using-chunk-upload.

Here's my controller code:
namespace FileUpload.Controllers
{
    [DisableRequestSizeLimit]
    public class UploadController : Controller
    {
        [HttpPost("upload/chunk")]
        public async Task SaveChunked(IList chunkFile, IList UploadFiles)
        {
            try
            {

                if ((chunkFile == null || !chunkFile.Any()) && UploadFiles != null && UploadFiles.Any())
                {
                    // File is smaller than chunk size:
                    // Upload to blob storage:

                    return;
                }

                if (chunkFile == null) throw new ArgumentException("No data uploaded");

                foreach (var file in chunkFile)
                {
                    var httpPostedChunkFile = HttpContext.Request.Form.Files["chunkFile"];
                    var chunkIndex = HttpContext.Request.Form["chunk-index"];
                    var totalChunk = HttpContext.Request.Form["total-chunk"];

                    using (var fileStream = file.OpenReadStream())
                    {
                        if (Convert.ToInt32(chunkIndex) <= Convert.ToInt32(totalChunk))
                        {
                            var streamReader = new MemoryStream();
                            fileStream.CopyTo(streamReader);
                            var byteArr = streamReader.ToArray();
                            var content = new byte[] { };

                            if (HttpContext.Session.Get("streamFile") != null)
                            {
                                content = HttpContext.Session.Get("streamFile").Concat(byteArr).ToArray();
                            }
                            else
                            {
                                content = byteArr;
                            }
                            HttpContext.Session.Set("streamFile", content);

                        }

                        if (Convert.ToInt32(chunkIndex) == Convert.ToInt32(totalChunk) - 1)
                        {
                            var fileArray = HttpContext.Session.Get("streamFile");

                            using (var fileStreams = new FileStream(httpPostedChunkFile.FileName, FileMode.Create))
                            {
                                foreach (var stream in fileArray)
                                {
                                    fileStreams.WriteByte(stream);
                                }

                                fileStreams.Seek(0, SeekOrigin.Begin);
                                HttpContext.Session.Remove("streamFile");
                                // new MemoryStream(myByteArray);
                                // Save file: await blockBlob.UploadFromStreamAsync(fileStreams);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
   }
}

But with large files the controller isn't even triggered.
Smaller files are fine. Multiple small files are fine as well.

The error:


Please assist.



7 Replies 1 reply marked as answer

SN Sevvandhi Nagulan Syncfusion Team October 1, 2020 03:03 PM UTC

Hi Paul,  
  
  
Greetings from Syncfusion support. 
  
  
By default, ASP.NET Core allows you to upload files up to 28 MB (approximately) in size. However, if you want to upload the large file, then please add the below configuration.  
  
  
1.     Create a web.config file in the root of the project and add the below code,  
  
<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
       <system.webServer> 
              <security> 
                      <requestFiltering> 
                             <requestLimits maxAllowedContentLength="2147483647" />  
                      </requestFiltering> 
              </security> 
       </system.webServer> 
</configuration> 
  
            Set your file size to the maxAllowedContentLength. Here we provided the maxAllowedContentLength for 2147MB.  

2.       Add the below configuration code in the Startup.cs file.  
  
   public void ConfigureServices(IServiceCollection services)  
        {  
            services.AddControllersWithViews();  
            services.Configure<IISServerOptions>(options => 
            { 
                options.MaxRequestBodySize = long.MaxValue; // you can customize the maximum file size as per your need 
 
            }); 
            services.Configure<FormOptions>(x => 
            { 
                x.ValueLengthLimit = int.MaxValue;  
                x.MultipartBodyLengthLimit = long.MaxValue; // you can customize the maximum file size as per your need 
 
            }); 
  
Please find the sample below,  
  
 

  
Reference links:  
  

  
  
Regards,  
Sevvandhi N  



PM Paul Meems October 5, 2020 07:28 AM UTC

Thanks for the reply and the sample.
I tried your code suggestions in my code, some of them I already had, but with the same problem.

Next, I tried your sample application and uploaded to my Azure account.
Although I still get connection errors, due to your retry mechanism I could eventually upload the files:


I will now compare your code with mine. I did see you are using some deprecated code.
I also submitted a support ticket to Microsoft Azure, hopefully they will give some advise on how to get rid of the connection aborts, because large files are now uploaded several times before their finished making the upload process take very long.


SN Sevvandhi Nagulan Syncfusion Team October 6, 2020 08:31 AM UTC

Hi Paul, 
 
 
Thanks for the update. 
 
 
We suspect that when the file is stored in Azure storage, the reported problem appears to be common. So we suggest that you check the common links below for more details. 









Regards, 
Sevvandhi N 



PM Paul Meems October 6, 2020 02:14 PM UTC

Thanks Sevvandhi for the suggestions.

The problem is earlier in the pipeline because when uploading larger files the controller is not even reached.
As said I also submitted a Microsoft Azure support ticket and I just got a new reply.
They can reproduce the problem and will investigate further.
Perhaps it is a Blazor issue.

I'll keep you posted when I got a solution or workaround from Microsoft.


PG Pon Geetha A J Syncfusion Team October 7, 2020 05:57 AM UTC

Hi Paul, 
  
Okay, we will be waiting for your futher updates. 
  
Regards, 
Geetha 



PM Paul Meems October 23, 2020 10:17 AM UTC

It's been a long battle but it seems we've identified the problem.
Microsoft Support from a different region and some of my colleagues working from home didn't have the reported problem.

In Azure I had set the HTTP Version to 2.0, when I set it back to 1.1 the problems went away as well.
So it seems a hop in my connection is dropping the v2.0 packages.

Hopefully this will help somebody else. It took me long enough ;)

Marked as answer

PO Prince Oliver Syncfusion Team October 26, 2020 08:10 AM UTC

Hi Paul, 

Thank you for sharing the solution with us. We are glad that the issue is resolved in your end. 

Regards, 
Prince 


Loader.
Up arrow icon