use*_*365 2 .net asp.net-mvc asp.net-web-api
我正在使用此代码处理文件上传到web api:
[HttpPost]
public async Task<IHttpActionResult> Post(string provider)
{
if (!Request.Content.IsMimeMultipartContent())
throw new Exception();
var streamProvider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(streamProvider); // FAILS HERE
foreach (var file in streamProvider.Contents)
{
var imageFilename = file.Headers.ContentDisposition.FileName.Trim('\"');
var imageStream = await file.ReadAsStreamAsync();
}
}
Run Code Online (Sandbox Code Playgroud)
但它在这里抛出一个错误: await Request.Content.ReadAsMultipartAsync(streamProvider);
错误是:读取MIME多部分正文部分时出错.内部异常是:
{"Cannot access a disposed object."}
Run Code Online (Sandbox Code Playgroud)
关于为什么会出现这个错误的任何想法?
我有类似的问题,但提供的解决方案对我不起作用,所以这是我的:你上传的文件与IIS的安全限制不匹配.
http://forums.asp.net/t/2062896.aspx?Error+reading+MIME+multipart+body+part+when+upload+image
<system.web>
<httpRuntime maxRequestLength="30000000" /> <!-- if you forget this one it does not work -->
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="30000000" />
</requestFiltering>
</security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6562 次 |
| 最近记录: |