title: Uploading and downloading large files ~50gb using ASP Core 2.2 api
body: <p>I'm struggling to provide ability in my ASP Core 2.2 app to upload and download large files, up to 50gb. Currently, for testing purposes, I'm saving the files on local storage but in future, I will move it to some cloud storage provider.</p>
  
  <p>Files will be sent by other server written in Java, more specifically it will be Jenkins plugin that sends project builds to my ASP Core server using <a href="https://github.com/box/box-java-sdk/blob/master/doc/files.md" rel="nofollow noreferrer">This library</a>.</p>
  
  <p>Currently, I use classic Controller class with HttpPost to upload the files, but this seems to me like not the best solution for my purposes since I won't use any webpage to attach files from client. </p>
  
  <pre><code>  [HttpPost]
    [RequestFormLimits(MultipartBodyLengthLimit = 50000000000)]
    [RequestSizeLimit(50000000000)]
    [AllowAnonymous]
    [Route("[controller]/upload")]
    public async Task&lt;IActionResult&gt; Upload()
    {
         var files = Request.Form.Files;
         SetProgress(HttpContext.Session, 0);
         long totalBytes = files.Sum(f =&gt; f.Length);
  
         if (!IsMultipartContentType(HttpContext.Request.ContentType))
                  return StatusCode(415);
  
         foreach (IFormFile file in files)
         {
              ContentDispositionHeaderValue contentDispositionHeaderValue =
                      ContentDispositionHeaderValue.Parse(file.ContentDisposition);
  
              string filename = contentDispositionHeaderValue.FileName.Trim().ToString();
  
              byte[] buffer = new byte[16 * 1024];
  
              using (FileStream output = System.IO.File.Create(GetPathAndFilename(filename)))
              {
                  using (Stream input = file.OpenReadStream())
                  {
                      long totalReadBytes = 0;
                      int readBytes;
  
                      while ((readBytes = input.Read(buffer, 0, buffer.Length)) &gt; 0)
                      {
                          await output.WriteAsync(buffer, 0, readBytes);
                          totalReadBytes += readBytes;
                          int progress = (int)((float)totalReadBytes / (float)totalBytes * 100.0);
                          SetProgress(HttpContext.Session, progress);
  
                          Log($"SetProgress: {progress}", @"\LogSet.txt");
  
                          await Task.Delay(100);
                      }
                  }
              }
          }
  
          return Content("success");
  
      }
  </code></pre>
  
  <p>I'm using this code now to upload files but for larger files >300mb it takes ages to start the upload. </p>
  
  <p>I tried looking for many articles on how to achieve this, such as:
  <a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-2.2#uploading-large-files-with-streaming" rel="nofollow noreferrer">Official docs</a>
  or 
  <a href="https://stackoverflow.com/questions/36437282/dealing-with-large-file-uploads-on-asp-net-core-1-0">Stack</a></p>
  
  <p>But none of the solutions seems to work for me since the upload takes ages and I also noticed that for files ~200MB(the largest file I could upload for now) the more data is uploaded the more my PC gets slower.</p>
  
  <p>I need a piece of advice if I am following the right path or maybe I should change my approach. Thank you.</p>