我正在构建一个Web应用程序,从Web表单中获取文件,并将它们放入Google Drive文件夹中.在提交表单时,我想运行一个带有google.script.run的云函数,同时将Form对象作为参数传递.
我的问题是,在通过表单对象后,我如何访问Code.gs中的文件?我想得到文件名和其他数据. 我的代码:
Index.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<form id="myForm" onsubmit="handleFormSubmit(this)">
<label for="FormControlFile">Select File:</label>
<input name="myFile" type="file" id="FormControlFile" multiple />
<button type="submit">Submit</button>
</form>
<?!= include('script'); ?>
</body>
</html>
Code.gs:
const folderId = "my folder id";
const folder = DriveApp.getFolderById(folderId);
function doGet() {
return HtmlService.createTemplateFromFile("index").evaluate();
}
function include(fileName) {
return HtmlService.createHtmlOutputFromFile(fileName).getContent();
}
function uploadFiles(formObject) {
//formObject.files??
}
Script.html:
<script>
function preventFormSubmit() {
const form = document.getElementById("myForm")
form.addEventListener("submit", (e) => {
e.preventDefault();
});
}
window.addEventListener("load", preventFormSubmit);
function handleFormSubmit(formObject) {
google.script.run.uploadFiles(formObject);
}
</script>
谢谢