I am trying to upload a simple text file to Google Drive in Angular using gapi, but I can't find how to actually populate the file. I managed to authenticate and create a file, and then I wanted to use the update function to update the file's contents as described here in the Google Drive API v3 documentation.
Here is my Angular code:
Creating the file:
createFile() {
return gapi.client.drive.files.create({
resource: {
name: `test.csv`
}
}).then(response => {
console.log("Response", response.result.id);
return response.result.id;
})
}
This creates the file and I can see it in my Drive's root folder. Then I try to add the contents of this file (using the file ID of the file I just created) but it is not clear to me from the documentation how to pass the content in the update call.
updateFile(fileId) {
return gapi.client.drive.files.update({
fileId: fileId,
body: "this is the content of my file"
}).then(response => {
console.log("Response", response);
})
}
I also tried to pass the content directly in the create call, based on the example they give in the documentation (link above)
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);
})
}
Though this doesn't work either.