将API从.NET框架重写为.netCore,获取System.notsupportedException'尝试获取文件流
我将一个项目迁移到.NET Core MVC,
- 以前的代码具有用于上传文档的API,将
- 上述代码重写的同一代码重写到下面的代码,使用的是“使用” Microsoft.aspnetcore.mvc.webapicompatshim“要获得httprequestmessage
[旧代码:在.net框架中工作正常]
public HttpResponseMessage UploadFile(string filetype)//old code
{
Stream file = Request.Content.ReadAsStreamAsync().Result;
string id;
id = DocumentHelper.SaveDocument(filetype, file);
return Request.CreateResponse<string>(HttpStatusCode.OK, id);
}
public HttpResponseMessage UploadFile(string filetype)//Re-Written Code
{
HttpRequestMessageFeature requestMessage = new HttpRequestMessageFeature(Request.HttpContext);
HttpRequestMessage httpRequestMessage = requestMessage.HttpRequestMessage;
Stream file = httpRequestMessage.Content.ReadAsStreamAsync().Result;
string id;
id = DocumentHelper.SaveDocument(filetype, file);
return httpRequestMessage.CreateResponse<string>(HttpStatusCode.OK, id);
}
[1]:https://i.sstatic.net /cc4af.png
尝试使用request.body与流读取器,并启用了
任何指针 。返回类型
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论