從 blob 在 Google 雲端硬碟中建立一個新檔案

 function createGoogleDriveFileWithBlob() {
  var blob,character,data,fileName,i,L,max,min,newFile,randomNmbr;//Declare variable names
  
  fileName = "Test Blob " + new Date().toString().slice(0,15);//Create a new file name with date on end
  
  L = 500;//Define how many times to loop
  data = "";
  max = 126;
  min = 55;

  for (i=0;i<L;i+=1) {//Loop to create data
    randomNmbr = Math.floor(Math.random()*(max-min+1)+min);//Create a random number
    //Logger.log('randomNmbr: ' + randomNmbr);
    character = String.fromCharCode(randomNmbr);
    
    //Logger.log('character: ' + character);//Print the character to the Logs
    data = data + character;
  };

  blob = Utilities.newBlob(data, MimeType.PLAIN_TEXT, fileName);//Create a blob with random characters

  newFile = DriveApp.createFile(blob);//Create a new file from a blob
  
  newFile.setName(fileName);//Set the file name of the new file
};