使用 javascript api 显示来自保管箱的图像

Display images from dropbox with javascript api

我正在尝试创建一个可以通过 Javascript API.

显示保管箱文件夹中所有图片的页面

我能够正确设置我的 Dropbox 应用程序,并且能够获取文件列表。

我卡在了 URL 的部分,我实际上可以用它来显示 HTML 中的图片。我尝试了以下代码,暂时尝试获取 1 张图像的 URL:

dbx.filesListFolder({path: ""})
    .then(function(response) {
        console.log(response);
        // ↑ this works!
        dbx.filesGetThumbnail({path: response.entries[0].path_display, format: "jpeg", size: "w64h64"})
            .then(function(result) {
                window.data = result;
                console.log(result);
            })
        // closures and rest of code...

检查 window.dataconsole.log(result),我似乎找不到任何 URL 我可以在我的 HTML.

中使用

有什么指示可以指引我朝着正确的方向前进吗?我还是 Dropbox 的新手 Javascript API.

感谢Greg

filesGetThumbnail 方法本身 return 没有 URL 缩略图数据。它 return 直接是原始缩略图数据。如果您希望 URL 在浏览器中本地显示,您可能需要这样的东西:

dbx.filesGetThumbnail({"path": "/test.jpg"})
  .then(function(response) {
    var img = document.createElement('img');
    img.src=window.URL.createObjectURL(response.fileBlob);
    document.body.appendChild(img);
  })
  .catch(function(error) {
    console.log("got error:");
    console.log(error);
  });

顺便说一句,您可以找到记录在案的所有 API v2 JavaScript SDK 方法 here

其他人也有同样的问题:) 现在 Dropbox JS Api returns base64 图像数据代替,所以你需要做这样的事情:

  var img = document.createElement('img');
  img.src = "data:image/jpg;base64, " + <data returned>;

data:image/jpg 取决于您请求的图像类型