Join BoxWorks in San Francisco Nov 12-13! Keynotes, product demos, and Box Master Classes. Reserve your spot!

Unable to Upload Files using API and Curl

New post

Comments

5 comments

  • Official comment
    cbetta

    I am so sorry, it seems we had a mistake in our cURL samples for uploads.

    The correct endpoint for uploads is on a different domain. I've updated the samples

    curl -i -X POST https://upload.box.com/api/2.0/files/content \
    -H 'Authorization: Bearer <TOKEN>' \
    -H "Content-Type: multipart/form-data" \
    -F attributes='{"name":"file.txt", "parent":{"id":"1234"}}' \
    -F file=@file.txt

    As for the issue you encounter with double/single quotes: behaviour of cURL between Linux/Mac/Windows is slightly different. You can choose to either use single quotes on the outside, and then use double quotes in the JSON, or use double quotes around the whole string and then use escaped double quotes in the JSON. For example:

    -F attributes="{\"name\":\"file.txt\", \"parent\":{\"id\":\"1234\"}}"

    I also recommend adding -i to your API calls so you can see the headers returned by the API, which is useful when the API returns an error.

     

    Comment actions Permalink
  • Box User

    This worked!! Please update the official documentation as I spent 3 days trying to get it to work. Thank you again!

    0
    Comment actions Permalink
  • cbetta

    Already fixed. So sorry about that!

    0
    Comment actions Permalink
  • RTSBox

    Hi CBetta the problem still exists and while trying to implement the curl that way we get this response 'API Upload did not contain a file part.' Please responsd as soon as possible. Thanks.

    0
    Comment actions Permalink
  • LinThaw

    Please share possible reasons and solutions for [API Upload did not contain a file part.] error.

    0
    Comment actions Permalink

Please sign in to leave a comment.