2

I received a link to shared folder from e-commerce company. The link is public and not shared with my dropbox account directly.

How do I get an url to the image that I can pass to either DownloadAsync method of the same sdk or simply HttpClient and well ... download it?

Ideally it would be the same link I get when I click on the image when viewing that shared folder in a browser.

https://www.dropbox.com/sh/{folder_hash}/{file_hash_maybe}/{filename}?dl=0

This is what I have tried:

using Dropbox.Api;
using Dropbox.Api.Files;
...
var accessToken = "abracadabra";
var sharedFolderUrl = "https://www.dropbox.com/sh/{folder_hash}?dl=0";

using (var dbx = new DropboxClient(accessToken))
{
    var sharedLink = new SharedLink(sharedFolderUrl);
    var sharedFiles = await dbx.Files.ListFolderAsync(path: "", sharedLink: sharedLink);

    // sharedFiles - has over 13,000 entries, I use cursor to get them all.
    foreach (var file in sharedFiles.Entries)
    {
        if (file.IsFile)
        {
            // tried this, but:
            // 1. it's crazy to loop through all 
            // 2. link.Response.Url gives me the same url to a shared folder for all items 
            var link = await dbx.Sharing.GetSharedLinkFileAsync(url: sharedFolderUrl, path: "/" + file.Name);
        }
    }        

}
Artur Kedzior
  • 3,994
  • 1
  • 36
  • 58

1 Answers1

2

Using the GetSharedLinkFileAsync method is the right way to programmatically download a file from a shared link. It actually gives both the metadata (in the link.Response in your code like you mentioned), as well as the file data directly (not via a URL).

To access the file data, you can use any of the GetContentAs... methods documented under IDownloadResponse as returned by GetSharedLinkFileAsync. In your code, that would look something like: link.GetContentAsStreamAsync() (or whichever one you want).

Alternatively, if you want to download the entire folder from the shared link, you can use the URL parameters documented in this help center article. (That may fail for very large folders though.)

Greg
  • 16,359
  • 2
  • 34
  • 44
  • Thanks for reply. The folder download fails (even in the browser) but looping through every single image with large set like in my case is ...well a bit crazy. Suggestion: since all images are public why not provide shareable url link within entries of `ListFolderResult`? Same link that is provided when viewing the folder in the browser. The reason I'm asking is because in my case I'm running this code on system A but image download and processing happens on system B, so in this code I would like to get public url and queue it for processing with system B (over night). – Artur Kedzior May 06 '20 at 09:13
  • 1
    Thanks for the feedback. I can't speak to why any particular feature was or wasn't implemented, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though. – Greg May 06 '20 at 13:59
  • Thanks a lot @Greg ! – Artur Kedzior May 06 '20 at 14:13