问题描述
我已经在Dropbox API应用程序控制台中设置了一个应用程序,对其进行了配置,设置了访问范围并生成了访问令牌。
我让客户端JS使用npm dropbox软件包来处理此代码。
<script>
import Dropbox from 'dropbox';
var ACCESS_TOKEN = 'MYACCESSTOKEN';
var SHARED_LINK = 'https://www.dropbox.com/s/0-0-0-0/Link.txt';
var dbx = new Dropbox.Dropbox({ accessToken: ACCESS_TOKEN });
dbx
.sharingGetSharedLinkFile({ url: SHARED_LINK })
.then(function (data) {
var blob = data.result.fileBlob;
var reader = new FileReader();
reader.addEventListener(
'loadend',function () {
console.log(reader.result);
},{ once: true }
);
reader.readAsText(blob);
})
.catch(function (error) {
console.log(error);
});
</script>
,这为我提供了控制台输出文件内容的功能。现在,我试图将其移动到我的节点后端。
var Dropbox = require('dropbox').Dropbox;
var fetch = require('isomorphic-fetch');
var ACCESS_TOKEN = 'MYACCESSTOKEN';
var dbx = new Dropbox({ accessToken: ACCESS_TOKEN,fetch: fetch });
dbx.filesDownload( {path: '/link.txt' })
.then(function(response) {
var blob = response.result
console.log(blob)
// var reader = new FileReader();
// reader.addEventListener('loadend',function () {
// res.status(200).text(reader.result);
// console.log(reader.result);
// },{once: true});
//reader.readAsText(blob);
});
}
此输出
{ name: 'Link.txt',path_lower: '/link.txt',path_display: '/Link.txt',id: 'id:PpUnRfeu2cwAAsdAAAAD3PgA',client_modified: '2020-07-10T22:12:01Z',server_modified: '2020-08-01T15:22:11Z',rev: '015abd27832sdb8d900000001e1d2b470',size: 110,is_downloadable: true,content_hash:
'1d46879a11f6dc9a720f5fd0sd79f53d6d4b1c7c6677523d55935e742bc0f921ab',fileBinary:
<Buffer 68 74 74 70 73 3a 2f 2f 6c 69 76 65 74 72 61 63 6b 2e 67 61 72 6d 69 6e 2e 63 6f 6d 2f 73 65 73 73 69 6f 6e 2f 35 30 31 36 61 38 36 34 2d 64 39 37 64 ... > }
很好奇,这里没有data.result.fileBlob,但我想我追赶fileBinary。由于节点中没有fileReader,因此我假设必须使用fs或其他库来解码二进制文件,但我无所适从查找示例。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)