Discuss Dropbox Developer & API
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 use the binary object inside body request, for example, some 010101101011010101010 binary code inside request instead of "/folder/filename.extension" . Because I am building a system client-server that a user can upload a file, sending by Post request to server, and the server must to take this file via $_ENV[] and insert it into a request to upload to Dropbox. And doesnt a way to server save temporary file inside your filesystem because the your provider is ephemeral, and so, because it i have to insert the file binary data inside request.
I will be grateful.
[Cross-linking for reference: https://stackoverflow.com/questions/72758417/how-to-upload-file-using-an-array-with-binary-data-file... ]
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:
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"
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
@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.
Ahh, thanks! Will do a deep dive into the documentation
Hi there!
If you need more help you can view your support options (expected response time for a 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!