.NET Core 128kb File size limit deployed to Azure App Service

谁说胖子不能爱 提交于 2021-02-19 04:17:47

问题


I have a .NET Core 2.0 web app running on an Azure App Service instance. When I try to upload a file using file.CopyToAsync(), the upload fails with no diagnostic output if the file is larger than 128kB. Some photo types like png just get chopped at 128kB, even when they're several mB in size.

When I try running locally, I can upload much larger files into my wwwroot/etc... folder on my local machine, so the problem seems specific to Azure App Services. I've looked up documentation on file size limits, etc., but I'm only seeing limits on the scale of 10/50 mB per file and 10/50 GB per app instance.

Specific implementation looks like this:

Directory.CreateDirectory(Path.Combine(_env.WebRootPath, uploadDir));
foreach (var file in files)
{
    try
    {
        var filePath = Path.Combine(_env.WebRootPath, uploadDir, file.FileName);
        using (var stream = new FileStream(filePath, FileMode.Create))
        {
            await file.CopyToAsync(stream);            
        }
    }
    catch (Exception ex)
    {
        throw;
    }
}

This runs with no errors or exceptions, but when I view the file system using Kudu (site.scm.azurewebsites.net), the file is listed with no size, and is inaccessible for download or viewing. Again, works perfectly well for file sizes at 128kB or less.

I can't find reference anywhere to such a limit per file with Azure App Services, so just wondering if anyone else has come across this before. Thanks


回答1:


I think I've solved it; going to post the answer here for others just in case, as this has gotten a few upvotes.

The files object I was looping over in the posted code snippet was a IList<IFormFile> type, which I was getting by casting the Request.Form.Files in the controller. Why I was doing this, I can't recall. Anyway, leaving the file list as the default IFormFileCollection that it gets bound to by MVC (the type on Request.Form.Files) seems to fix it. It also solved another problem I was having of certain file extensions not uploading.

I can't seem to figure out why it was breaking when I was calling new List<IFormFile>(Request.Form.Files), but the lesson here should be to avoid all unnecessary type castings or conversions.



来源:https://stackoverflow.com/questions/57117392/net-core-128kb-file-size-limit-deployed-to-azure-app-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!