我正在尝试将文件从 Node.js 上传到我的保管箱帐户。我在 Dropbox 开发人员控制台上创建了一个应用程序,然后生成了一个访问 token 。
我正在使用以下代码读取文件并将其上传到保管箱:
app.get('/uploadfile', function (req, res) {
if (req.query.error) {
return res.send('ERROR ' + req.query.error + ': ' + req.query.error_description);
}
fs.readFile(__dirname + '/files/pictureicon.png','utf8', function read(err, data) {
if (err) {
throw err;
}
fileupload(data);
});
});
function fileupload(content) {
request.put('https://api-content.dropbox.com/1/files_put/auto/proposals/icon.png', {
headers: { Authorization: 'Bearer TOKEN-HERE', 'Content-Type': 'image/png'
}, body: content}, function optionalCallback (err, httpResponse, bodymsg) {
if (err) {
return console.log(err);
}
console.log("HERE");
});
}
通过使用上面的代码,我的文件出现在我的保管箱帐户中,但我无法打开它。它出现了以下错误。
知道我可能做错了什么吗?我在上面的代码中犯了错误吗?
最佳答案
问题可能是您读取了编码为 utf-8
的文件,即使它不是文本文件。您应该读取缓冲区(通过简单地 not providing a encoding argument )。
关于javascript - 从 node.js 上传文件到 Dropbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36009601/