.NET Core 128kb文件大小限制已部署到Azure App Service [英] .NET Core 128kb File size limit deployed to Azure App Service

查看:48
本文介绍了.NET Core 128kb文件大小限制已部署到Azure App Service的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Azure App Service实例上运行的.NET Core 2.0 Web应用程序.当我尝试使用 file.CopyToAsync()上载文件时,如果文件大于128kB,则上载将失败并且没有诊断输出.诸如png之类的某些照片类型即使大小为数mB,也会被切成128kB.

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.

当我尝试在本地运行时,可以将更大的文件上传到本地计算机上的 wwwroot/etc ... 文件夹中,因此该问题似乎特定于Azure App Services.我查阅了有关文件大小限制的文档,等等,但是我只看到每个文件10/50 mB和每个应用程序实例10/50 GB的大小限制.

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.

具体实现如下:

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;
    }
}

这没有任何错误或异常,但是当我使用Kudu(site.scm.azurewebsites.net)查看文件系统时,文件没有大小列出,并且无法下载或查看.同样,对于128kB或更小的文件大小,效果很好.

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.

使用Azure App Services在任何地方都找不到对每个文件的限制的参考,所以只是想知道以前是否有人遇到过这种情况.谢谢

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

推荐答案

我认为我已经解决了;为了以防万一,在这里将答案发布给其他人,因为这有一些反对意见.

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

我在发布的代码片段中循环显示的 files 对象是 IList< IFormFile> 类型,我是通过投射 Request.Form获得的控制器中的.Files .为什么我要这样做,我不记得了.无论如何,将文件列表保留为MVC绑定到的默认 IFormFileCollection (在 Request.Form.Files 上的类型)似乎可以解决该问题.这也解决了另一个我没有上传某些文件扩展名的问题.

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.

当我调用 new List< IFormFile>(Request.Form.Files)时,我似乎无法弄清为什么它中断了,但是这里的教训应该是避免所有不必要的类型强制转换或转化.

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.

这篇关于.NET Core 128kb文件大小限制已部署到Azure App Service的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆