Unable to Upload Files using API and Curl

新規投稿

コメント

5件のコメント

  • 正式なコメント
    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.

     

    コメントアクション パーマリンク
  • Box User

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

    0
    コメントアクション パーマリンク
  • cbetta

    Already fixed. So sorry about that!

    0
    コメントアクション パーマリンク
  • 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
    コメントアクション パーマリンク
  • LinThaw

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

    0
    コメントアクション パーマリンク

サインインしてコメントを残してください。