我如何在谷歌应用程序脚本中创建一个大文件? [英] How can i create a big file in google drive with google app script?

查看:80
本文介绍了我如何在谷歌应用程序脚本中创建一个大文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用谷歌应用程序脚本在谷歌驱动器中创建一个大文件。该文件合并了三个文件。我的代码是:

i try create a big file in google drive using google apps script. This file merged three files. My code is:

    function unirFicheros(idDirectorio,nombreFichero, numeroFicheros){
      var nombreTotal=nombreFichero;
      var strTotal="";
      var docTotal = DocsList.createFile(nombreTotal, strTotal);
      Utilities.sleep(5000);
      Logger.log("SE CREA TOTAL: " + numeroFicheros);
      for(var i=1;i<=numeroFicheros;i++){
           Logger.log("ENTRO EN EL FOR");
           var nombrePartes=nombreFichero+i+".csv";
           Logger.log("NOMBREPARTES: " + nombrePartes);
           var id=listFilesInFolder(idDirectorio,nombrePartes);
           var docPartes = DocsList.getFileById(id);
           Utilities.sleep(5000);
           Logger.log("Existe el fichero");
           var str = docPartes.getContentAsString();
           Logger.log("UNE LA CADENA");
           strTotal = strTotal+str;
           Utilities.sleep(5000);
           docTotal.replace(strTotal);
           Utilities.sleep(30000);
        }
        return docTotal;
    }

发生的错误是:

The error occurs is:


Ejecuciónfallida:El archivo backup_actuaciones_PROD supera eltamañode archivomáximopermitido。
(执行失败:文件backup_actuaciones_PROD文件大小超过允许的最大值)。

Ejecución fallida: El archivo backup_actuaciones_PROD supera el tamaño de archivo máximo permitido. (Execution failed: File backup_actuaciones_PROD file size exceeds the maximum allowed.)

我试图生成没有格式的文件,因为互联网说这些文件更大。实际上,我的文件有44 MB,但我需要427 MB。

I trying to generate my file without format because internet says that these files are bigger. Actually, my file have 44 MB, but i need 427 MB.

此致。

推荐答案

DriveApp.createFile() 包含一个注意事项... 如果内容大于10MB 则抛出异常。我预计这个限制也会影响 DocsList.createFile() DocsList.replace()

DriveApp.createFile() includes a note that it... Throws an exception if content is larger than 10MB. I expect that this limitation also affects DocsList.createFile() and DocsList.replace().

避免需要处理 docTotal 的全部内容,您可能会获得更好的结果。使用 File.append( ) 来添加每个文件的内容:

You might have better results by avoiding the need to handle the entire contents of docTotal. Use File.append() to add the content of each file:

       ...
       var str = docPartes.getContentAsString();
       Logger.log("UNE LA CADENA");
       docTotal.append(str);
       ...

这篇关于我如何在谷歌应用程序脚本中创建一个大文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆