Home > Net >  How to add json file to specific folder in Google Apps Script?
How to add json file to specific folder in Google Apps Script?

Time:02-23

This code working good, but file goes to the root folder. I not found any helpfully in internet...

function saveAsJSON() {
  var blob,file,fileSets,obj;
  
  obj = {//Object literal for testing purposes
    key:"value"
  }

/**
 * Creates a file in the users Google Drive
 */
  
  fileSets = {
    title: 'file.json',
    mimeType: 'application/json'
  };
  
  blob = Utilities.newBlob(JSON.stringify(obj), "application/vnd.google-apps.script json");
  file = Drive.Files.insert(fileSets, blob);
  Logger.log('ID: %s, File size (bytes): %s, type: %s', file.id, file.fileSize, file.mimeType);

}

CodePudding user response:

ANSWER

You need to use the parents property in your fileSets and put your desired drive folder ID, enter image description here

  • Related