I'm using this code to process a file upload to a web api:
[HttpPost]
public async Task<IHttpActionResult> Post(string provider)
{
if (!Request.Content.IsMimeMultipartContent())
throw new Exception();
var streamProvider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(streamProvider); // FAILS HERE
foreach (var file in streamProvider.Contents)
{
var imageFilename = file.Headers.ContentDisposition.FileName.Trim('\"');
var imageStream = await file.ReadAsStreamAsync();
}
}
but it throws an error here: await Request.Content.ReadAsMultipartAsync(streamProvider);
The error is: Error reading MIME multipart body part. The inner Exception is:
{"Cannot access a disposed object."}
any ideas on why this error is coming up?