I cannot successfully post image data to the `doPost` function in GAS from this HTML file:
<!DOCTYPE html>
<html>
<body>
<form method="POST" action="deployUrl" enctype="multipart/form-data">
<input type="file" name="image" accept="image/*">
<input type="submit" value="Upload">
</form>
</body>
</html>
Here is my GAS code:
function doGet(e) {
return HtmlService.createTemplateFromFile('index').evaluate();
}
function doPost(e) {
console.log(e);
console.log("e.parameter: " + JSON.stringify(e.parameter));
console.log("e.parameters: " + JSON.stringify(e.parameters));
console.log("e.contentLength: " + e.contentLength);
console.log("e.files: " + JSON.stringify(e.files));
if (e.files && e.files.image) {
var fileBlob = e.files.image;
console.log("File Blob: " + fileBlob.getName());
var folder = DriveApp.getFolderById('myFolerId');
var file = folder.createFile(fileBlob);
return ContentService.createTextOutput('File uploaded: ' + file.getUrl());
} else {
return ContentService.createTextOutput('No file uploaded or e.files is undefined.');
}
}
Please let me know how to correct it.
Additionally, I want to maintain the sequence of doGet → HTML → doPost → HTML because I intend to use Gemini for image analysis afterward and transition to a page with the input content and analysis results.