asp.net webapi 上传图片
public async Task<HttpResponseMessage> Images()
{
// 检查是否是 multipart/form-data
if (!Request.Content.IsMimeMultipartContent("form-data"))
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
HttpResponseMessage response = null;
try
{
// 设置上传目录
var provider = new MultipartFormDataStreamProvider(@"F:\\webapi\\UpLoad");
// 接收数据,并保存文件
await Request.Content.ReadAsMultipartAsync(provider);
response = Request.CreateResponse(HttpStatusCode.Accepted);
}
catch
{
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
return response;
}
谢谢
定,精,简,俭