cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Dropbox API v2

Dropbox API v2

Madhavi T.
Explorer | Level 4

I am trying out Dropbox API V2 using HTMl,JavaScript by making API calls with XMLHTTPRequest. To upload a file onto Dropbox the API requires a 'data-binary' property to be set with the path of the file you want to upload. Below is the reference link of API and its parameters:

 

https://www.dropbox.com/developers/documentation/http/documentation#files-upload

 

I am able to set all the other properties and API is able to create a blank file at the specified path for 'Dropbox-API-Arg', however unable to pass the file from my machine to the API call.

 

How can I set data-binary with the path of the file to upload, specifically in XMLHTTPRequest?

 

Thanks in advance.

4 Replies 4

Greg-DB
Dropbox Staff
The HTTP documentation has a curl example, where curl's "data-binary" option is used to supply the file request body from a local file.

In JavaScript in the browser, you don't have direct access to use the user's local filesystem, so when using XMLHttpRequest, you can supply the file data directly by using the "send" method. There's an example here:

https://stackoverflow.com/documentation/dropbox-api/409/uploading-a-file/18435/uploading-a-file-from...

Madhavi T.
Explorer | Level 4

Thanks for the useful information Greg. ☺

 

I tried out the way you suggested and it seems that if I write a string (any sentence) in the value of the variable 'content' and pass it to the request keeping the path as a text file, it indeed creates a text file with the contents in it. However, I would like to pass the contents of an PDF file/image file to the request. When I try to get a file thorugh HTML input and pass it to the request, it simply creates a 0 bytes file in Dropbox with no content in it, and says the file can not be previewed. I believe this is happening because PDF files contains binary data and I am unable to do a binary-string conversion using JavaScript.

 

Could you please let me know if this is something you can help with. Any help is greatly appreciated. Thanks in advance. 

Greg-DB
Dropbox Staff
There's another example for uploading from a file from an input tag here:

https://stackoverflow.com/documentation/dropbox-api/409/uploading-a-file/1359/uploading-a-file-via-j...

Madhavi T.
Explorer | Level 4

Awesome...Thanks a ton Greg!!!  I just tried it and it seems to be working for me... ☺

 

This is a great forum. I have found a good platform in case I am stuck on anything!!!

Need more support?