简体   繁体   中英

File Upload Endpoint on ASP.NET web api corrupts file

I'm using .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...

What am I doing wrong? Thanks, Adi.

The Owin Handler is the responsible for the errors. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM