[英]How to upload a file in a folder GOOGLE DRIVE API
所以我试试这个,我使用我的文件夹 ID,但这不起作用,我的文件已创建,但我的文件夹中没有 go。 在 Google Drive 的文档中只有这个例子。 当我在 Slack 上提交表单时,将我的数据推送到 Google 电子表格上,然后在星期一自动生成一张票。 现在我想将我的电子表格推送到我的云端硬盘中的一个特殊文件夹中。我可以通过其他方式提供我的文件吗?
async function createSpreadsheet(filename, body) {
const ID_FOLDER_DRIVE = MY_ID;
try {
const fileMetaData = {
'name': filename,
parents: [ID_FOLDER_DRIVE]
}
const media = {
mimeType: 'text/csv',
body: body
}
const res = await drive.files.create({
requestBody: {
resource: fileMetaData,
mimeType: 'application/vnd.google-apps.spreadsheet'
},
media: media
})
return res.data
} catch (error) {
throw error
}
}
async function generatePublicUrl(id) {
console.log({ id })
try {
await drive.permissions.create({
fileId: id,
requestBody: {
role: 'reader',
type: 'anyone',
},
});
/*
webViewLink: View the file in browser
webContentLink: Direct download link
*/
const result = await drive.files.get({
fileId: id,
fields: 'webViewLink, webContentLink',
});
return result.data.webViewLink
} catch (error) {
throw error
}
}
在您的情况下,如何进行以下修改?
const fileMetaData = {
'name': filename,
parents: [ID_FOLDER_DRIVE]
}
const media = {
mimeType: 'text/csv',
body: body
}
const res = await drive.files.create({
requestBody: {
resource: fileMetaData,
mimeType: 'application/vnd.google-apps.spreadsheet'
},
media: media
})
const fileMetaData = {
name: filename,
parents: [ID_FOLDER_DRIVE],
mimeType: 'application/vnd.google-apps.spreadsheet'
}
const media = {
mimeType: 'text/csv',
body: body
}
const res = await drive.files.create({
requestBody: fileMetaData,
media: media
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.