Javascript 使用google脚本将BLOB数组附加到google文档
我有一个脚本,用户可以将图片提交到google文档,但当我上传多张图片并输入文件时,google脚本不会附加所有图片。如何重写我的代码,使其附加我用Javascript 使用google脚本将BLOB数组附加到google文档,javascript,google-apps-script,blob,Javascript,Google Apps Script,Blob,我有一个脚本,用户可以将图片提交到google文档,但当我上传多张图片并输入文件时,google脚本不会附加所有图片。如何重写我的代码,使其附加我用选择的所有图像 form.theFile是我上传的所有图片的数组吗?因为Form.theFile[0]不起作用 code.gs: function doGet() { return HtmlService.createHtmlOutputFromFile('index'); } function serverFunc(theForm) {
选择的所有图像
form.theFile是我上传的所有图片的数组吗?因为Form.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)
}
}
<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>
index.http:
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)
}
}
<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>
适用于。然后,您可以通过以下方式访问每个文件:
for (i = 0; i < theForm.theFile.length-1; i++) {
var blob = theForm.theFile[i];
var file = folder.createFile(blob);
}
(i=0;i
var blob=文件[i]的形式;
var file=folder.createFile(blob);
}
我还建议查看此示例,但改用DocsList服务:
希望这能帮助您解决问题。不幸的是,我无法让服务器端部分正常工作。无论如何,我仍然希望为我的用户使用“multiple”标记,因此这不起作用。这是我能找到的唯一可行的解决方案,允许用户在一个“submit”中上载多个文件,但是如果您让“multiple”参数起作用,请告诉我,因为我同意这是一个更优雅的解决方案。我没有发现任何东西。但是现在我只是强迫我的用户上传一个压缩文件,然后我就可以解压ServerSide了,因为服务器部分也很麻烦。我也不明白。如果你解决了问题,请让世界知道:)