0
我想使用GAS的HtmlService上傳文件,但它不起作用。 我在這個主題中發現了信息Uploading file using Google Apps Script using HtmlService,但它不符合我的問題。 這裏是描述我的問題的例子:使用html服務將文件上傳到谷歌應用程序腳本
Code.gs:
function doGet() {
return HtmlService.createTemplateFromFile("index").evaluate();
}
//For some reasons, this function has to be in code.gs
funcion getHTML() {
var html = "<form id='myform'>"+
"<input name='myfile'>"+
"</form>"+
"<div data-formname='myform'> Submit form </div>";
return html;
}
function uploadFile(file) {
DriveApp.createFile(file); *//Doesn't work :/*
}
的Javascript:
$(document).on("click","div", function(e) {
var idform = $(this).data("formname");
if (idform)
sendForm(idform);
});
function trigger() {
google.script.run.withsuccesshandler(setHTML).getHTML();
}
function setHTML(html) {
$("#myHTML").html(html);
}
function sendForm(idForm) {
var formElements = document.getElementById("idForm").elements;
var form = {};
for (var key in formElements) form[key] = formElements[key];
google.script.run.withsuccesshandler().uploadFile(form["myfile"]);
}
的index.html
<body onload="trigger()">
<div id='myHTML'></div>
</body>
下面的例子可能是有用的:[窗體]( https://developers.google.com/apps-script/guides/html/communication#forms) – wchiquito