【发布时间】:2017-04-09 09:38:01
【问题描述】:
我正在使用 asp.net 核心来构建 API。我有一个请求,允许用户使用此代码上传个人资料图片
[HttpPost("{company_id}/updateLogo")]
public async Task<IActionResult> updateCompanyLogo(IFormFile imgfile,int company_id)
{
string imageName;
// upload file
if (imgfile == null || imgfile.Length == 0)
imageName = "default-logo.jpg";
else
{
imageName = Guid.NewGuid() + imgfile.FileName;
var path = _hostingEnvironment.WebRootPath + $@"\Imgs\{imageName}";
if (imgfile.ContentType.ToLower().Contains("image"))
{
using (var fileStream = new FileStream(path, FileMode.Create))
{
await imgfile.CopyToAsync(fileStream);
}
}
}
.
.
但它不断返回此异常:Form key or value length limit 2048 exceeded
请求
http://i.imgur.com/25B0qkD.png
更新:
我试过这段代码,但它不起作用
services.Configure<FormOptions>(options =>
{
options.ValueLengthLimit = int.MaxValue; //not recommended value
options.MultipartBodyLengthLimit = long.MaxValue; //not recommended value
});
【问题讨论】:
-
它
services.Configure<FormOptions>在 .NET Core 2.0 中工作 -
对我也不起作用。
-
试试这个对我有用的解决方案。 stackoverflow.com/a/71085281/14550822
标签: asp.net asp.net-core