【发布时间】:2018-03-24 12:35:50
【问题描述】:
我正在尝试使用 Angular Js 和 WEB API 浏览文件并将其从客户端上传到服务器。我使用输入文件类型让用户选择文件并将文件发布到 WEB API。在 Web API 中,我收到以下错误“调用 HttpRequest.GetBufferlessInputStream 后不支持此方法或属性。”
我正在使用以下代码:-
public IHttpActionResult UploadForm()
{
HttpResponseMessage response = new HttpResponseMessage();
var httpRequest = System.Web.HttpContext.Current.Request;
if (httpRequest.Files.Count > 0)
{
foreach (string file in httpRequest.Files)
{
var postedFile = httpRequest.Files[file];
var filePath = System.Web.HttpContext.Current.Server.MapPath("~/UploadFile/" + postedFile.FileName);
postedFile.SaveAs(filePath);
}
}
return Json("Document Saved");
}
当我尝试从 HTTP 请求获取文件时出现此错误...我应该更新 Web 配置中的任何内容吗?
请帮我解决这个问题..
【问题讨论】:
标签: c# asp.net-web-api httprequest wcf-web-api