[英]Problems Downloading files using Dropbox JavaScript SDK
當我使用 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 成功回調,但找不到下載的文件。
在 Node.js 中,Dropbox API v2 JavaScript SDK 下載樣式的方法在它們傳遞給回調(代碼中的response
)的對象的fileBinary
屬性中返回文件數據。
你可以在這里找到一個例子:
https://github.com/dropbox/dropbox-sdk-js/blob/master/examples/javascript/node/download.js#L20
因此,您應該能夠以response.fileBinary
訪問數據。 它不會自動為您將其保存到本地文件系統,但您可以根據需要這樣做。
您需要使用 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);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.