I have a JavaScript based Google Apps script that iterates through all files in Drive and converts MS files to Google format. I am using Drive API to upload and convert. Everything seems to work fine, except when I have a file in a Drive sub folder. When the file is uploaded back to Drive, I cannot define a parent folder, so it goes directly to the root.
I have a handle on the parent folder ID, but when I add "parents : folderID" to the JSON String, I do not see any change in the upload path.
This is my upload and convert function, is there any way to modify this to define a parent folder? I'm totally lost with the API... Can anyone assist?
var uploadFile = JSON.parse(
UrlFetchApp.fetch("https://www.googleapis.com/upload/drive/v2/files?uploadType=media&convert=true",
{
method: "POST",
contentType: officeFile.getMimeType(),
payload: officeFile.getBlob().getBytes(),
parents: ['id' : folderID], <<<<<<<<<<<<<<<<< this line
headers: {
"Authorization" : "Bearer " + ScriptApp.getOAuthToken()
},
muteHttpExceptions: true
}).getContentText());
parents[ ]
description. I guess as long as you set the folderID right you should be able to upload to the folder. Please double check your folderID. Also, there is already a v3 available for the Drive API so I think that it is worth looking at. Good luck! – gerardnimo