23

I have code that does async file uploads which works fine on my dev vm but after I deployed it to the client system, I keep getting this error:

"error writing mime multipart body part to output stream"

I know this is the line that is throwing the error but I can't seem to figure out why:

//Read the form data and return an async task.
await Request.Content.ReadAsMultipartAsync(provider);

The file size was only 1MB and I even tried different file types with much smaller sizes. Why would this occur, I need ideas

Mutu Yolbulan
  • 1,052
  • 1
  • 8
  • 21
  • 1
    Assuming your request hasn't changed between when the service was deployed on the dev vm and the client's vm, can you check if there is something else going on...like are you using a `MultipartFormDataStreamProvider`, if yes, can you check if the folder to where the files are being created has proper permissions for your app to write...what i mean is that this could be a false alarm and the problem could be something else...also just in case, can you paste how your request looks like? (you need not copy the 1mb file part, but rest of the stuff should be good) – Kiran Jun 13 '14 at 03:44
  • Yeah, I went back to the service, logged the innerStack and realized it was a permissions issue with IISIuser. When I gave it modify rights, it worked!. thanks. write an answer so I can accept it maybe? – Mutu Yolbulan Jun 13 '14 at 03:56

3 Answers3

56

Since the error message is mentioning about an error while writing to output stream, can you check if the folder to where the response is being written out has necessary permissions for your application to write.

Kiran
  • 56,921
  • 15
  • 176
  • 161
  • 7
    or check the folder is already exist or not , because in web api deployment to azure not upload empty folders , this is my case and solved ..thank you +1 – Hisham Apr 08 '16 at 23:21
  • 2
    Folder was not there in my case. Thanks. – Baqer Naqvi Apr 19 '16 at 14:41
  • 1
    just fyi, I have the same problem but my folder has been created and the permissions are fine. Still trying to figure out what else is causing it. – Jacky Cheng Mar 22 '17 at 09:03
  • Cant believe, I spent an hour debugging with a solution hiding in plain site. Good job Challa – Pradip May 12 '17 at 14:04
2

You can also get this error if a file with the same name already exists in the destination folder.

Brett Pennings
  • 1,489
  • 14
  • 19
  • Why this answer doesn't have more up votes is surprising. This is a nearly undocumented exception. In fact the main Microsoft documentation for this method doesn't include exceptions at all. – iGanja Apr 23 '20 at 01:22
1

I had this issue but I had already set permissions on the destination folder.

I fixed the problem by setting permissions on the App_Data folder (I think this is where the file gets temporarily stored after being uploaded).

jag
  • 517
  • 6
  • 16