【发布时间】:2021-07-23 20:29:18
【问题描述】:
上传成功并返回 id。并试图 drive.files.list 太。它存在。但驱动器中不存在文件?这是什么?我尝试通过 id 在特定文件夹中上传。文件上传位置在哪里?
const { google } = require('googleapis');
const fs = require('fs');
const credentials = require('./credentials.json');
const scopes = [
'https://www.googleapis.com/auth/drive'
];
const auth = new google.auth.JWT(
credentials.client_email, null,
credentials.private_key, scopes
);
const drive = google.drive({ version: 'v3', auth });
(async () => {
const fileMetadata = {
name: 'naruto.jpg'
};
const media = {
mimeType: 'image/jpeg',
body: fs.createReadStream('naruto.jpg')
};
const res = await drive.files.create({
q: `'1PhND1fjEDnL63BbrLmw2V4M4B6jIfP8Q' in parents`,
resource: fileMetadata,
media: media,
fields: 'id'
});
console.log(res.data);
})();
【问题讨论】:
标签: node.js google-api google-drive-api service-accounts google-api-nodejs-client