I'm trying to do an image preview functionality through google app script.
This is my code:
code.gs
function doGet(e) {
return HtmlService.createTemplateFromFile('form')
.evaluate() // evaluate MUST come before setting the NATIVE mode
.setTitle('Details')
.setSandboxMode(HtmlService.SandboxMode.NATIVE);
}
form.html
<!DOCTYPE html>
<html>
<head>
<script>
var loadFile = function(event) {
var reader = new FileReader();
reader.onload = function(){
var output = document.getElementById('preview');
output.src = reader.result;
};
reader.readAsDataURL(event.target.files[0]);
};
</script>
</head>
<body>
<input type='file' id="imgInp" onchange="loadFile(event)" />
<img id="preview" src="#" alt="your image" />
</body>
</html>
When I deploy this code, it gives me the following error:
In Safari: undefined is not a constructor (evaluating 'new FileReader()')
In Chrome:
Uncaught TypeError: FileReader is not a function
I doubted that FileReader
may not be understood by the Google App Script
interpreter(?), but I found this SO question and it seems to exist and be used.
I tried using IFRAME
mode instead of NATIVE
and it seem to work. It's weird though. I want to make it work through NATIVE