I don´t know if there is a way on making this work, but I want to make a form with input type=file
.
But when I submit the form it won't work cause of the input type=file
and cause of my access permission is set to me only in the Google Apps Script.
Well the code goes like this, I'm just showing the base code which I'm having trouble with. Whenever I remove the line with the input file it will submit the form and add in a spreadsheet the value I've input in the first name text box. And I've notice that it also works when I leave the input file line, when I change the permissions in my script, when I publish the code as a web app, and in the "Who has access to the app" put "Anyone, even anonymous", the thing is that I don't want that anyone could access the webapp. I'm just thinking on rewritting the gs code to check the user accessing the web app, but I'm not sure if this would be safe.
GS Code:
function doGet() {
var template = HtmlService.createTemplateFromFile('HtmlName');
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);}
function processForm(formObject) {
var formBlob = formObject.myFile;
var driveFile = DriveApp.createFile(formBlob);
var firstName = formObject.firstName;
DriveApp.getFolderById("anyID").addFile(driveFile);
ss.appendRow([formObject.firstName,
]);}
Html File
<!DOCTYPE html>
<html>
<body>
<form class="w3-container" id="myForm" onsubmit="handleFormSubmit(this); ">
<p>
<input class="w3-input" name="myFile" type="file">
<input class="w3-input" type="text" name="firstName">
<p>
<input class="w3-button" type="submit" value="Submit">
</form>
</body>
<script>
// Prevent forms from submitting.
function preventFormSubmit() {
var forms = document.querySelectorAll('form');
for (var i = 0; i < forms.length; i++) {
forms[i].addEventListener('submit', function(event) {
event.preventDefault();
}); } }
window.addEventListener('load', preventFormSubmit);
function handleFormSubmit(formObject) {
google.script.run.withSuccessHandler(updateUrl).processForm(formObject);
}
</script>
</html>