3

I'm getting the following error when uploading a file via my .NET Core application hosted as an Azure Web App:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

This was tested in Postman and timed out with a 404 Not Found at around 22 seconds.

My application code is as follows, stripping out the extra stuff:

    public async Task<IActionResult> PostDocuments(ICollection<IFormFile> files)
    {
        foreach (var file in files)
        {
                string path = Path.Combine(uploadsDir, file.FileName);

                //Uploading file to "uploads" to be staged. Doesn't get past here.
                using (var stream = new FileStream(Path.Combine(uploadsDir, file.FileName), FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }

                //Uploading files to Azure
                if (await _azure.UploadFile(path, file.FileName)
                {
                    // Stuff to add file to database
                }
                else
                {
                    return StatusCode(400, "Could not upload one or all of your files.");
                }
            }
            else
            {
                return StatusCode(400, "One or all of your files are empty, have invalid types, or are targeting mismatched buildings or floors.");
            }
        }

        return StatusCode(201, files);
    }

I believe my issue is simply that the request is taking too long and Azure is cancelling it to maintain the integrity of the application. It also sounds like from my research that maybe I need to allow the application to start the Azure upload and move onto adding it to the database. However, from my testing locally, it appears the long part of the process is even before I get to any of my controller's logic. Is there a better way to do this?

jackmusick
  • 311
  • 2
  • 7
  • Do any of your other endpoints work? e.g. does api/foos return anything? – trevorc Feb 06 '17 at 21:10
  • Everything in the application works, including uploading files that take less than 22 seconds to upload. – jackmusick Feb 06 '17 at 21:12
  • How large is the file upload you are testing that is timing out? There is a setting on how large of a file size to accept. – trevorc Feb 06 '17 at 21:14
  • 50MB. Files around 10-15MB seem to work. Additionally, the file uploads when I'm testing locally, so I don't believe it's application specific necessarily. – jackmusick Feb 06 '17 at 21:15
  • 1
    If you are hosting via IIS I would look at [this](http://stackoverflow.com/questions/288612/how-to-increase-the-max-upload-file-size-in-asp-net#18531025) link to just confirm your azure web app doesn't have a setting less than 50MB. – trevorc Feb 06 '17 at 21:21
  • That was it. Really thought it was a timeout issue, so my search terms were off completely. If you wanted to post that as the answer and take credit, feel free. I'm not too familiar with Stack Overflow etiquette so trying not to step on your toes. – jackmusick Feb 06 '17 at 21:54

1 Answers1

5

If you are hosting your .net core application via IIS you can still add a web.config file to the root of your application. When you get a timeout or 404 error on a larger file upload chances are it is maxAllowedContentLength issue.

There are some good answers here that describe this in more detail.

The short answer would be to add this to your web.config file if you are hosting with IIS.

<system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="52428800" /> <!--50MB-->
      </requestFiltering>
    </security>
  </system.webServer>
Community
  • 1
  • 1
trevorc
  • 3,023
  • 4
  • 31
  • 49
  • I'm confused. Doesn't "Azure Web App" indicate it's not IIS hosted? What about when it isn't IIS hosted? – w00ngy Jul 31 '18 at 14:04