Skip to main content

Get HTTP 400 error when invoking upload file API (https://upload.box.com/api/2.0/files/content). The message says “Malformed stream”, but gives no additional information. Tried the exact payload as specified in this box documentation page (https://developer.box.com/guides/uploads/direct/file/) and run it in Postman and still get the same error.


Request Payload:


POST /api/2.0/files/content HTTP/1.1
Host: upload.box.com
Authorization: Bearer rACCESS_TOKEN]
content-length: 343
content-type: multipart/form-data; boundary=------------------------9fd09388d840fef1

--------------------------9fd09388d840fef1
content-disposition: form-data; name="attributes"

{"name":"test.txt", "parent":{"id":"0"}}
--------------------------9fd09388d840fef1
content-disposition: form-data; name="file"; filename="test.txt"
content-type: text/plain

Test file text.

--------------------------9fd09388d840fef1--

Error Response:


{
"code": "bad_request",
"help_url": "http://developers.box.com/docs/#errors",
"status": 400,
"message": "Malformed stream",
"type": "error"
}

Hello 👋


In Postman, instead of using the raw tab - I like to use the form-data tab. The collection should automatically have the attributes object ready to fill out and the file selector ready to pick a file.


It also has the code tab which will show to code it is running based on the language you select in the drop down.



When not using Postman, I also suggest using one of our SDKs since it does all the upload logic for you without manually having the create the body since it can be tricky. Is there a reason you cannot use a SDK?


Thanks,

Alex, Box Developer Advocate 🥑


Thanks Alex! that works.


Reply