5

这类似于我之前的问题: Downloading images from public shared folder 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(???);
        }
    }        
}

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

4

1 回答 1

3

对于任何给定的子文件夹,要列出其内容,您需要ListFolderAsync再次调用,使用相同的sharedLink值,但path为子文件夹提供一个值,相对于共享链接的根文件夹。

例如,如果您列出文件夹共享链接的内容,并且其中一个条目是名称为“SomeFolder”的文件夹,那么要列出“SomeFolder”的内容,您需要进行如下调用:

await dbx.Files.ListFolderAsync(path: "/SomeFolder", sharedLink: sharedLink);
于 2020-05-27T13:27:11.423 回答