网络接口上传错误.MIME 多部分流的预期结束.MIME 多部分邮件不完整
本文关键字:多部 MIME 结束 错误 分流 网络接口 | 更新日期: 2023-09-27 18:37:11
我一直在按照本教程支持文件上传作为MVC4的WebAPI的一部分:http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx。
当我的控制器收到请求时,它会抱怨"MIME 多部分邮件不完整"。有没有人对如何调试它有任何提示?我尝试将流的位置重置为 0,以防在它到达处理程序之前有其他东西读取它。
我的 HTML 看起来像这样:
<form action="/api/giggl" method="post" enctype="multipart/form-data">
<span>Select file(s) to upload :</span>
<input id="file1" type="file" multiple="multiple" />
<input id="button1" type="submit" value="Upload" />
</form>
和我的控制器的 Post 方法,如下所示:
public Task<IEnumerable<string>> Post()
{
if (Request.Content.IsMimeMultipartContent())
{
Stream reqStream = Request.Content.ReadAsStreamAsync().Result;
if (reqStream.CanSeek)
{
reqStream.Position = 0;
}
string fullPath = HttpContext.Current.Server.MapPath("~/App_Data");
var streamProvider = new MultipartFormDataStreamProvider(fullPath);
var task = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t =>
{
if (t.IsFaulted || t.IsCanceled)
Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception);
var fileInfo = streamProvider.FileData.Select(i =>
{
var info = new FileInfo(i.LocalFileName);
return "File uploaded as " + info.FullName + " (" + info.Length + ")";
});
return fileInfo;
});
return task;
}
else
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Invalid Request!"));
}
}
我错过了什么明显的东西吗>
您可以尝试将"name"属性添加到输入文件中吗?
<input name="file1" id="file1" type="file" multiple="multiple" />