4

I have a web app where user can upload a picture of his logo using dropbox api im able to save the file to a dropbox folder which is great

however i want to get the download link so using my angular client ill be able to set the img src tag and show the image

I've been using this implementation:

String url = client.sharing().createSharedLinkWithSettings("/" + clientId + "/logo." + fileName[1]).getUrl();

however as the name implies im getting a share link which is basically a web page with the image i only need the image is it possible?

naoru
  • 2,149
  • 5
  • 34
  • 58

3 Answers3

3

Yes, use DbxUserFilesRequests.getTemporaryLink instead. That will give you a temporary link that points directly to the file data.

Greg
  • 16,359
  • 2
  • 34
  • 44
  • i had to unmark the answer since as stated its a temporary link and after few hours i get 410 from dropbox. what i need is a permanent link – naoru Feb 23 '18 at 13:41
3

the answer @Greg gave is correct but i needed a permanent link i was able to use the answer from here Dropbox API - Get permanent link for my media?

and here is my implementation

String[] fileName = file.getOriginalFilename().split("\\.");
InputStream in = file.getInputStream();
client.files().uploadBuilder("/" + clientId + "/logo." + fileName[1]).withMode(WriteMode.OVERWRITE).uploadAndFinish(in);
log.debug("Successfully uploaded image to drop box account");
SharedLinkMetadata meta = client.sharing().createSharedLinkWithSettings("/" + clientId + "/logo." + fileName[1]);
String url = meta.getUrl();
// now we need to strip any other url params and append raw=1;
url = url.split("\\?")[0];
url = url + "\\?raw=1";
naoru
  • 2,149
  • 5
  • 34
  • 58
  • Note that per [the help article](https://www.dropbox.com/help/desktop-web/force-download), it's best to fully parse the URL in order to modify the parameters, instead of just performing raw string modifications like this. – Greg Feb 23 '18 at 16:27
3

This worked for me and was much easier than the solutions above, per this article:

To get a direct download link, replace the www.dropbox.com with dl.dropboxusercontent.com

EDIT: I've also discovered that you can add the query parameter ?dl=1 (dl meaning download and 1 meaning "enabled") to a shared link and that will make it a direct-download link as well. This is likely more reliable (long-term) than the method above.

Preston Badeer
  • 2,658
  • 1
  • 20
  • 21
  • 2
    This answer is way too underrated! The entire damn internet is looking for this solution. LOL!! Thanks @Preston Badeer – PhillipJacobs Sep 13 '22 at 07:04