You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
Amicao
3 years agoExplorer | Level 3
How to upload file via Curl with Binary object input?
Hello, good evening for all. I would like to know, how I can to upload file using a Curl request, or PHP Curl request, with the upload file request.
But instead I use the parameter o filepath, I us...
Greg-DB
3 years agoDropbox Staff
[Cross-linking for reference: https://stackoverflow.com/questions/72758417/how-to-upload-file-using-an-array-with-binary-data-file-object-to-dropbox-usin ]
When uploading a file to Dropbox using the Dropbox API /2/files/upload endpoint, the app needs to supply several different types of things, including:
- the parameters for the upload call, documented under "UploadArg" and sent in the "Dropbox-API-Arg" request header: this includes a "path" parameter that tells Dropbox where Dropbox account you want to put the uploaded file. Refer to the documentation for your network client for information on how to set request headers.
- the bytes of the file data to upload, sent in the request body: this should be the exact file contents that you want to put in the connected Dropbox account at the path specified as noted above. Exactly how you retrieve the file data and put it in the request body will depend on the specific of your scenario. Refer to the documentation for your network client for information on how to set the request body.
For example, using curl on the command line, this would upload a file to the remote path "/test_605632.txt" in Dropbox, telling curl to send the contents of the local file at the local (relative) path "test/test.txt" (the "@" is a way of telling curl to read from the local filesystem):
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer <ACCESS_TOKEN>" \
--header "Dropbox-API-Arg: {\"path\":\"/test_605632.txt\"}" \
--header "Content-Type: application/octet-stream" \
--data-binary test/test.txt
And for comparison, this would upload a file to the remote path "/test_605632.txt" in Dropbox, telling curl to send the data "some data" itself (not from a local file):
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer <ACCESS_TOKEN>" \
--header "Dropbox-API-Arg: {\"path\":\"/test_605632.txt\"}" \
--header "Content-Type: application/octet-stream" \
--data-binary "some data"
- karanag3 years agoExplorer | Level 4
Hi,
I am facing kind of the same problem. My Code is below but it uploading a corrupted image, any ideas what exactly I am doing wrong? I am trying to build my app using no-code tool AppGyver
const imagePath = inputs.imagePath; // (This line takes the path of the image)var path = "/Pictures/testPicturreABC12345.jpg";var content = "@" + imagePath;var accessToken = "sl.BLX6BjKTDsrOpArs74Bk32Pg09Ukns0u3YUCsDnoagiOJdx2hq6iCZezCKlWc-53v8E6IVOaU3Tu0OAOGMrxc5KIVeihAn51f5hZ0x3EKpCJdEKuykWIz4SAeC4WcjXpKiSrhWC8";var result;var xhr = new XMLHttpRequest();xhr.onreadystatechange = function() {if (xhr.readyState === 4) {result = xhr.responseText;return result;}};xhr.open("POST", uploadUrl, true);xhr.setRequestHeader("Authorization", "Bearer " + accessToken);xhr.setRequestHeader("Content-type", "application/octet-stream");xhr.setRequestHeader("Dropbox-API-Arg", '{"path": "' + path + '"}');xhr.send(content);- Greg-DB3 years agoDropbox Staff
karanag In your code, you're sending the data in your 'content' variable, which just contains the string '"@" + imagePath', not the actual file data at that path. In the examples in the Dropbox API documentation, the "@" is a way of telling curl on the command line to read from the local filesystem at that path. That wouldn't necessarily work in other environments, such as using XMLHttpRequest like you are here. You'll need to update your code to pass in the actual file data. Please refer to the documentation for your platform for information on accessing file data.
- karanag3 years agoExplorer | Level 4
Ahh, thanks! Will do a deep dive into the documentation
About Discuss Dropbox Developer & API
Make connections with other developers
797 PostsLatest Activity: 2 days agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!