Search code examples
dropbox-api

Dropbox - API get the download link of a file


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?


Solution

  • 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";