从 Dropbox 上的公开共享文件夹和子文件夹下载图像

Downloading images from publicly shared folders and sub-folders on Dropbox

这与我之前的问题类似:

我有这段代码(简化版)需要从公共共享文件夹和所有子文件夹下载所有图像。

using Dropbox.Api;
using Dropbox.Api.Files;
...
// AccessToken - get it from app console 
// FolderToDownload - https://www.dropbox.com/sh/{unicorn_string}?dl=0

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

    // var sharedFiles = await dbx.Files.ListFolderAsync(path: "", sharedLink: sharedLink, recursive: true); 
    // "recursive: true" throws:  Error in call to API function "files/list_folder": Recursive list folder is not supported for shared link.

    foreach (var entry in sharedFiles.Entries)
    {
        if (entry.IsFile)
        {
            var link = await dbx.Sharing.GetSharedLinkFileAsync(url: _dropboxSettings.FolderToDownload, path: "/" + entry.Name);
            var byteArray = await link.GetContentAsByteArrayAsync();
        }

        if (entry.IsFolder)
        {
            var subFolder = entry.AsFolder;
            // var folderContent = await dbx.Files.ListFolderAsync(path: subFolder.Id);
            // var subFolderSharedLink = new SharedLink(???);
        }
    }        
}

如何列出所有子文件夹的条目?

对于任何给定的子文件夹,要列出其内容,您将需要再次回调 ListFolderAsync,使用相同的 sharedLink 值,但提供 path 值子文件夹,相对于共享 link.

的根文件夹

例如,如果您列出共享文件夹 link 的内容,其中一个条目是名称为 "SomeFolder" 的文件夹,则列出 "SomeFolder" 的内容],您需要拨打如下电话:

await dbx.Files.ListFolderAsync(path: "/SomeFolder", sharedLink: sharedLink);