Google drive script not uploading file larger than

2019-05-15 23:52发布

问题:

I copied a basic example to upload a file to Google drive automatically using Google-script. Drive.Files.insert works for images (png files) and DriveApp.createFile works for text file types. But i am trying to upload a backup.tar.bz2 file which is larger than 10M. Every time the process executes it uploads 10MB and it stops. I read somewhere that there is no 10MB limit on non-google file types and i could upload file as big as i want (i think its 1 TB). I am manually able to upload the same file via the google drive web page.

Can some one please point me to the right direction or give me an example of code that works for > 10MB binary object? Thank you.

UPDATE: I am able to upload a zip file less than 10MB in size.

function uploadFile() {
  var image = UrlFetchApp.fetch('http://example.com/files/backup.tar.bz2').getBlob();
  var file = {
    title: 'backup.tar.bz2',
    mimeType: 'application/bz2'
  };
 // file = Drive.Files.insert(file, image); -- ANOTHER WAY OF DOING IT
    DriveApp.createFile(image);
  //Logger.log('ID: %s, File size (bytes): %s', file.id, file.fileSize);
  Logger.log(image.getName() + "    " + image.getBytes());
};

回答1:

I'm afraid the documentation to DriveApp.createFile mentions

Throws an exception if content is larger than 10MB

for all variants except the Blob one, but I suspect it's just an oversight. It looks related to the POST quota and is mentioned anyway in several support tickets (see for instance #552, #2806).