Trying to utilize the 'browser' version of the Google Drive API, which seems to mostly adhere to Nodejs syntax. However, there are limited examples available beyond the basic hello world example for the browser.
Currently, the goal is to create a folder and then generate a simple JSON config file within that folder as a demonstration. Yet, upon executing the code, only an empty file named 'Untitled' appears in my Google Drive.
Below is a snippet of the file creation process, which returns as successful:
this.MEM.config = {
categories : {},
createdOn : Date.now()
}
let fileMetadata = {
name : 'config.json',
parents : [this.MEM.parent]
}
let media = {
mimeType : 'application/json',
body : JSON.stringify(this.MEM.config)
}
query = {
resource: fileMetadata,
media: media,
fields: 'id'
}
console.log(query);
try {
res = await gapi.client.drive.files.create(query);
} catch(err) {
throw err;
}
console.log(res);
The execution of this code does not result in any errors:
{
"result": {
"id": "1OI0ttFr11UH1__XAlSnyUil5hpp6mScB"
},
"body": "{\n \"id\": \"1OI0ttFr11UH1__XAlSnyUil5hpp6mScB\"\n}\n",
"headers": {
"cache-control": "no-cache, no-store, max-age=0, must-revalidate",
"content-encoding": "gzip",
"content-length": "67",
"content-type": "application/json; charset=UTF-8",
"date": "Thu, 29 Apr 2021 20:26:13 GMT",
"expires": "Mon, 01 Jan 1990 00:00:00 GMT",
"pragma": "no-cache",
"server": "GSE",
"vary": "Origin, X-Origin"
},
"status": 200,
"statusText": "OK"
}
Instead of successfully creating a 'config.json' file within the designated folder with the stringified object, only an Untitled file appears at the root of my Google Drive.