Reputation: 2227
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?
Upvotes: 4
Views: 5625
Reputation: 2717
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.
Upvotes: 4
Reputation: 2227
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";
Upvotes: 3
Reputation: 16930
Yes, use DbxUserFilesRequests.getTemporaryLink
instead. That will give you a temporary link that points directly to the file data.
Upvotes: 3