以下是代码:
[HttpPost]
public async Task<HttpResponseMessage> LowResImage(int id)
{
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var provider = new MultipartMemoryStreamProvider();
try
{
await Request.Content.ReadAsMultipartAsync(provider);
foreach (var item in provider.Contents)
{
if (item.Headers.ContentDisposition.FileName != null)
{
}
}
return Request.CreateResponse(HttpStatusCode.OK);
}
catch (System.Exception e)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
}
}
我可以一步一步地执行直到:
await Request.Content.ReadAsMultipartAsync(provider);
在此时,它永远不会完成。
为什么我的await从不返回?
更新
我正在尝试使用curl POST到此操作,命令如下:
C:\cURL>curl -i -F filedata=@C:\LowResExample.jpg http://localhost:8000/Api/Photos/89/LowResImage
我也尝试使用以下HTML进行POST操作,但出现了同样的情况:
<form method="POST" action="http://localhost:8000/Api/Photos/89/LowResImage" enctype="multipart/form-data">
<input type="file" name="fileupload"/>
<input type="submit" name="submit"/>
</form>
await
之后也要设置断点。有时候使用异步/等待时,它不会跳转到下一行(根据我的经验)。 - Micah