本文介绍了Google驱动器脚本无法上传大于10MB的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我复制了一个基本示例,使用Google脚本自动将文件上传到Google驱动器。 Drive.Files.insert适用于图像(png文件),DriveApp.createFile适用于文本文件类型。但我想上传一个大于10M的backup.tar.bz2文件。每次执行该过程时,都会上传10MB并停止。我在某处读到,非google文件类型没有10MB的限制,我可以上传文件大小(我想它的1 TB)。我手动能够通过谷歌驱动器网页上传相同的文件。



有人可以请我指出正确的方向,还是给我一个适用于> 10MB二进制对象的代码示例?谢谢。

更新:我可以上传一个小于10MB大小的zip文件。

  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); - 另一种做法
DriveApp.createFile(image);
//Logger.log('ID:%s,文件大小(字节):%s',file.id,file.fileSize);
Logger.log(image.getName()++ image.getBytes());
};


解决方案

恐怕文档提及

变种除了 Blob 之外,但我怀疑这只是一个疏忽。它看起来与相关,无论如何都在几张支持票中提及(请参阅, )。


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());
};
解决方案

I'm afraid the documentation to DriveApp.createFile mentions

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).

这篇关于Google驱动器脚本无法上传大于10MB的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 14:12