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?

6
  • Do any of your other endpoints work? e.g. does api/foos return anything? Commented Feb 6, 2017 at 21:10
  • Everything in the application works, including uploading files that take less than 22 seconds to upload. Commented Feb 6, 2017 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. Commented Feb 6, 2017 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. Commented Feb 6, 2017 at 21:15
  • 1
    If you are hosting via IIS I would look at this link to just confirm your azure web app doesn't have a setting less than 50MB. Commented Feb 6, 2017 at 21:21

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

1 Comment

I'm confused. Doesn't "Azure Web App" indicate it's not IIS hosted? What about when it isn't IIS hosted?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.