从Dropbox上的公共共享文件夹下载图像 [英] Downloading images from publicly shared folder on Dropbox

查看:77
本文介绍了从Dropbox上的公共共享文件夹下载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从电子商务公司收到一个指向共享文件夹的链接.该链接是公开的,没有直接与我的保管箱帐户共享.

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

如何获取可传递给相同sdk的DownloadAsync方法或仅HttpClient的图像的URL,然后下载它?

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

这是我尝试过的:

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);
        }
    }        

}

推荐答案

使用 GetSharedLinkFileAsync 方法是从共享链接以编程方式下载文件的正确方法.实际上,它既提供元数据(在您提到的代码中的 link.Response 中),也直接提供文件数据(不通过URL).

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.)

这篇关于从Dropbox上的公共共享文件夹下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆