问题描述
我已经开发了一个ASP.NET核心Web API,可以将文件从一个地方上传到另一个地方。我使用邮递员测试API。默认情况下,ASP.NET Core在上传文件时最多接受28 MB。对于IIS express方法,我增加了wev.config文件中maxAllowedContentLength的大小;对于Kestrel方法,我增加了MaxRequestBodySize的大小。但是,所有这些方法在文件大小高达200 MB的情况下都可以正常工作,但是上传大于200 MB的文件大小会失败,甚至[disableRequestSizeLimit]也将失败。我将maxAllowedContentLength和MaxRequestBodySize的值设置为大于1 gb。请向我建议一种在ASP.NET Core Web API中上传大于1 GB的大文件的方法。任何帮助表示赞赏。
IIS Express:
router.beforeEach((to,from,next)=>{
// console.log(store.state);
// console.log($store.state);
console.log(this.$store.state);
// if(this.$store.state.user.loggedIn){
// next('/login');
}else
next();
})
茶est:
<requestfiltering>
<!-- Measured in Bytes -->
<requestLimits maxAllowedContentLength="1073741824" />
<!-- 1 GB-->
</requestfiltering>
解决方法
对于IIS,除非在“请求过滤”中设置maxAllowedContentLength。 您还需要这样设置: 如果要删除文件上传限制,可以将其设置为null。
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = xxx;
});
如果您在IIS中运行服务器,则除了设置MaxRequestBodySize属性外,还必须删除请求过滤模块。