【发布时间】:2020-03-10 02:21:24
【问题描述】:
我可以成功地将我上传的图片保存在我的公共上传文件夹中并集成谷歌驱动器api,但它似乎正在上传一个空文件。
我应该从我的 req.files 数据中将什么放入 Google Drive API 的 body 参数
{name: 'country.jpg',data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 48 00 48 00 00 ff ed 26 0c 50 68 6f 74 6f 73 68 6f 70 20 33 2e 30 00 38 42 49 4d 04 04 00 00 00 00 00 22 ... 246290 more bytes>,size: 246340,encoding: '7bit',tempFilePath: '',truncated: false,mimetype: 'image/jpeg',md5: '8890c8336c58d854d490b41fa6ec0ad4',mv: [Function: mv]}
这是我经过身份验证后的 Google Drive API 调用。
const drive = google.drive({ version: "v3", auth });
drive.files.create({
media: {
mimeType: "image/jpeg",
body: // WHAT TO PUT HERE
},
resource: {
name: "photo.jpg"
// if you want to store the file in the root, remove this parents
//parents: ['folder id in which he file needs to be stored.']
},
fields: "id"
})
.then(function(resp) {
//console.log("RESPONSE");
console.log(resp, "resp");
})
.catch(function(error) {
console.log("ERROR");
console.log(error);
});
【问题讨论】:
标签: node.js express google-api google-drive-api google-api-nodejs-client