[英]File Upload Endpoint on ASP.NET web api corrupts file
I'm using .Net Framework 4.7 ASP.NET Web Api我正在使用 .Net Framework 4.7 ASP.NET Web Api
After uploading the files to the endpoint, I noticed the files are corrupted.将文件上传到端点后,我注意到文件已损坏。
[HttpPost]
public async Task UploadFile([FromODataUri] string key)
{
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var provider = await Request.Content.ReadAsMultipartAsync(new MultipartMemoryStreamProvider());
var file = provider.Contents.Single();
//get a corrupted file + size of file has increased significantly
var fileBytes = await file.ReadAsByteArrayAsync();
}
*I Also tried working with ReadAsStreamAsync and then read all the bytes, but looks like the data is still changed... *我也尝试使用 ReadAsStreamAsync 然后读取所有字节,但看起来数据仍然改变......
What am I doing wrong?我究竟做错了什么? Thanks, Adi.谢谢,阿迪。
The Owin Handler is the responsible for the errors. Owin 处理程序负责错误。 No solution were until now.直到现在还没有解决方案。 Just a recommendation to not bother with it and just create another service for file uploads.只是建议不要打扰它,只需为文件上传创建另一个服务。 good luck, Still waiting for answer btw.祝你好运,顺便说一句,还在等待答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.