1

当我使用 filesDownload() 时,我需要弄清楚我的文件在哪里下载。我没有看到文件目标的参数。这是我的代码:

require('isomorphic-fetch'); 
var Dropbox = require('dropbox').Dropbox;
var dbx = new Dropbox({ accessToken: 'accessToken', fetch});

dbx.filesDownload({path: 'filepath}).
  then(function(response) {
  console.log(response);
})
.catch(function(error) {
  console.log(error);
});

当我运行代码时,我得到了一个成功的回调,但我在任何地方都看不到该文件。

我需要知道我的文件下载到哪里以及如何在我的函数中指定文件目标。

谢谢,杰拉德

我已经使用了 SDK 文档 ( http://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesDownload__anchor )中描述的函数,但我不知道我的文件在哪里。

预期结果:文件下载到 Dropbox 到我指定的路径。

实际结果:我从 Dropbox 成功回调,但找不到下载的文件。

4

2 回答 2

1

在 Node.js 中,Dropbox API v2 JavaScript SDK 下载样式的方法在fileBinary它们传递给回调(response在您的代码中)的对象的属性中返回文件数据。

你可以在这里找到一个例子:

https://github.com/dropbox/dropbox-sdk-js/blob/master/examples/javascript/node/download.js#L20

因此,您应该能够以response.fileBinary. 它不会自动为您将其保存到本地文件系统,但您可以根据需要这样做。

于 2018-12-31T14:55:07.667 回答
1

您需要使用 fs 模块将二进制数据保存到文件中。

dbx.filesDownload({path: YourfilePath})
    .then(function(response) {
      console.log(response.media_info);
          fs.writeFile(response.name, response.fileBinary, 'binary', function (err) {
                if (err) { throw err; }
                console.log('File: ' + response.name + ' saved.');
              });
    })
    .catch(function(error) {
      console.error(error);
    });
于 2019-07-09T11:01:36.223 回答