Skip to main content

Box API Upload file error: Malformed stream

  • September 4, 2023
  • 4 replies
  • 354 views
Box API Upload file error: Malformed stream

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 [ACCESS_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"

}


Did this topic help you find an answer to your question?

4 replies

smartoneinok Box
Forum|alt.badge.img
  • Senior Developer Advocate
  • 181 replies
  • September 5, 2023

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 🥑


  • Author
  • New Participant
  • 1 reply
  • September 7, 2023

Thanks Alex! that works.


  • Participating Frequently
  • 5 replies
  • April 23, 2024

Yes I cannot use SDK since I am working on a platform. Please can you explain how to create the body manually


rbarbosa Box
  • Developer Advocate
  • 553 replies
  • April 23, 2024

Please create a new post and elaborate on your situation.


The “I cannot use SDK” does not help us identify the issue.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings