使用Google脚本将blob数组附加到Google文档

append an array of blobs to a google doc using google script

本文关键字:Google 文档 blob 脚本 使用 数组      更新时间:2023-09-26

我有一个脚本,用户可以提交图片到谷歌文档,但当我上传多个图片与文件输入,谷歌脚本不追加所有的图像。我该如何重写我的代码,使它附加所有我选择的图像与<input type="file" multiple />

给。我上传的所有图片的数组?因为给。theFile[0]不起作用

code.gs:

function doGet() {
  return HtmlService.createHtmlOutputFromFile('index');
}
function serverFunc(theForm) {
   doc = DocumentApp.openById("my top-secret id...");
   var img=doc.appendParagraph(theForm.theFile.getName()+":'n").setIndentStart(4).appendInlineImage(theForm.theFile)
   //resize image to fit in page if necessary
   while(img.getWidth()>750){
     img.setWidth(img.getWidth()/1.1).setHeight(img.getHeight()/1.1)
   }
}

index.http:

   <form style="outline:2px solid blue;">
      <input type="file" name="theFile" multiple />
      <input type="button"  value="UpLoad" id="button" onclick="google.script.run.serverFunc(this.parentNode)" />
   </form>

适用于http://www.fyneworks.com/jquery/multiple-file-upload/#。然后,您可以通过以下方式访问每个文件:

for (i = 0; i < theForm.theFile.length-1; i++) { 
  var blob = theForm.theFile[i];
  var file = folder.createFile(blob);
}

我还建议看看这个例子,但使用DocsList服务代替:https://developers.google.com/apps-script/guides/html/communication形式