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
Matthew S.22
9 years agoExplorer | Level 4
Javascript to Run Download Function on My Files?
Greetings, In a previous discussion, I solved how to upload files to pages in my app via a web form. Now I need to dynamically provide a "download" link to the file that was previously attached ...
- 9 years ago
Hi Matthew, the filesDownload method is the right way to directly download a file from a Dropbox account using the JavaScript SDK.
What do you have so far and what's giving you trouble in particular? There's a sample of using sharingGetSharedLinkFile available here for reference. When using filesDownload you would pass in a path (instead of a URL), but handling the response is the same.
For example, switching in the method, it would look something like this:
dbx.filesDownload({path: '/test.txt'}) .then(function(response) { var downloadUrl = URL.createObjectURL(response.fileBlob); var downloadButton = document.createElement('a'); downloadButton.setAttribute('href', downloadUrl); downloadButton.setAttribute('download', response.name); downloadButton.setAttribute('class', 'button'); downloadButton.innerText = 'Download: ' + response.name; document.getElementById('results').appendChild(downloadButton); }) .catch(function(error) { console.error(error); });
- 9 years agoYes, you can download with the shared link. For example, my version in my last post using filesDownload only requires the path, and not shared link.
Matthew S.22
Explorer | Level 4
Greg,
Yes, that's the code I used, and it does get me to the file. However, the problem is, the user will not know the "shared link." The way this app works is, people upload a file for a page, then come back to that page to see the file that was uploaded to it. As far as I can tell, the only way to see the shared link is to go to the DropBox page.
Is there a way to get the file another way, without the shared link?
Thanks,
Matthew
Greg-DB
9 years agoDropbox Staff
Yes, you can download with the shared link. For example, my version in my last post using filesDownload only requires the path, and not shared link.
- Matthew S.229 years agoExplorer | Level 4
Hi Greg,
Got it! It's working now.
After using the DropBox API for a while, I have come to really like the Javascript elements. I just find it challenging to locate examples. There is a pattern to the API calls, but each one is different enough that I need to see specific code.
Now I can upload a file to a specific page, and can also download the file that was uploaded on that page. I may need to return later for deeper methods: delete the file from the page, or overwrite an existing file with a newly uploaded one.
As I confirm the methods for each action, I'm planning to document them, either here or on jsfiddle.
Thanks,
Matthew
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,912 PostsLatest Activity: 37 minutes 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!