这类似于我之前的问题: Downloading images from publicly 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(???);
}
}
}
如何列出所有子文件夹的条目?
答案 0 :(得分:3)
对于任何给定的子文件夹,要列出其内容,您需要使用相同的ListFolderAsync
值再次调用sharedLink
,但要为子文件夹提供一个path
值,相对于共享链接的根文件夹。
例如,如果列出文件夹共享链接的内容,并且条目之一是名为“ SomeFolder”的文件夹,然后列出“ SomeFolder”的内容,则需要像:
await dbx.Files.ListFolderAsync(path: "/SomeFolder", sharedLink: sharedLink);