【发布时间】:2020-07-03 05:16:29
【问题描述】:
我正在尝试使用gapi 将一个简单的文本文件上传到 Angular 中的 Google Drive,但我找不到实际填充文件的方法。我设法验证并创建了一个文件,然后我想使用update 函数来更新文件的内容,如here in the Google Drive API v3 documentation 所述。
这是我的 Angular 代码:
创建文件:
createFile() {
return gapi.client.drive.files.create({
resource: {
name: `test.csv`
}
}).then(response => {
console.log("Response", response.result.id);
return response.result.id;
})
}
这会创建文件,我可以在驱动器的根文件夹中看到它。然后我尝试添加这个文件的内容(使用我刚刚创建的文件的文件 ID),但是从文档中我不清楚如何在 update 调用中传递内容。
updateFile(fileId) {
return gapi.client.drive.files.update({
fileId: fileId,
body: "this is the content of my file"
}).then(response => {
console.log("Response", response);
})
}
我还尝试根据他们在文档中给出的示例(上面的链接)直接在 create 调用中传递内容
createFile() {
return gapi.client.drive.files.create({
resource: {
name: `test.csv`
},
media: {
body: "this is the content of my file"
}
}).then(response => {
console.log("Response", response.result.id);
})
}
虽然这也不起作用。
【问题讨论】:
-
嗨@vdvaxel,你如何使用/加载gapi?