I was wondering if it was possible to have a file type validation within an upload app script. I want to limit the types of files being uploaded to images only (based on file extensions). I haven't provided my code because I'm not even sure if it's possible.
0
votes
1 Answers
0
votes
I'm afraid it can't be done using UiApp because the file name is not available from within the doGet function. This is handled in the browser without access from apps Script.
Running a simple demo code like below will show that we just can get the widget's type and that no other method is available. The validators are useless in this case since the file name is not available.
function doGet(e) {
var app = UiApp.createApplication().setTitle('test');
var fPanel = app.createFormPanel();
var panel = app.createVerticalPanel();
var text = app.createTextBox();
var submitButton = app.createSubmitButton('<B>Submit</B>');
//file upload
var upLoad = app.createFileUpload();
var handler = app.createClientHandler().forTargets(text).setText(upLoad);
upLoad.setName('thefile').addChangeHandler(handler);
app.add(fPanel.add(panel.add(upLoad).add(text).add(submitButton)));
return app;
}
demo online here (no doPost function so it will always return an error on submitting)
You can achieve that using html service quite simply using client javaScript.