Im trying to save some dynamically generated data (json) to a (new) file on my google drive using JS but i keep getting these unhelpful errors on my POST.
At first I thought I was POSTing to the wrong address, but after changing the data content the error changed from 404 to 400 so now i suspect that the error is formatting related (since i dont understand this multipart stuff so well).
code is like:
function gDriveSaveProject(data, gDriveFolderID, currentProj, callback )
{
const boundary = '-------314159265358979323846';
const delimiter = "\r\n--" + boundary + "\r\n";
const close_delim = "\r\n--" + boundary + "--";
var metadata = {
'title': currentProj + ".lo",
'mimeType': 'application/json',
'parents' : [{'id' : gDriveFolderID}]
};
var multipartRequestBody =
delimiter +
'Content-Type: application/json\r\n\r\n' +
JSON.stringify(metadata) +
delimiter +
'Content-Type: application/json\r\n' +
'Content-Transfer-Encoding: base64\r\n' +
'\r\n' +
btoa(JSON.stringify(data)) +
close_delim;
var request = gapi.client.request({
'path': '/upload/drive/v2/files',
'method': 'POST',
'params': {'uploadType': 'multipart'},
'headers': {
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
},
//'body': "" // using this gives me 400 instead of 404
'body': multipartRequestBody
});
request.execute(callback);
}
the code is based on the google drive sdk example, but using dynamically created data instead of a uploaded file and a target directory instead of the root.
thanks