I try to upload file to my ‘mysitename’ Google Site. I using this script, but it does not work
function doGet(e) {
var app = UiApp.createApplication().setTitle("Upload");
var formContent = app.createVerticalPanel();
formContent.add(app.createFileUpload().setName('thefile'));
formContent.add(app.createSubmitButton());
var form = app.createFormPanel();
form.add(formContent);
app.add(form);
return app;
}
function doPost(e) {
try{
var fileBlob = e.parameter.thefile;
var pages = SitesApp.getSite('site', 'mysitename').getChildren();
var attachments = pages[0].getAttachments();
attachments[0].setFrom(fileBlob);
}catch(e){
Logger.log(e.message);
}
}
I catch error “Cannot call method “setFrom” of undefined” last modal window “Error encountered: An unexpected error occurred”
It’s works! But i do not know, how to use this circular from documentation “Sets the data, content type, and name of this attachment from a Blob. Throws an exception for web attachments.” What is mean this “Throws an exception for web attachments”? I’ll be forced to use “try-catch-exception”
Pls, help me to do it!
I think the error is in the line
The documentation says
So, if you are within a domain, use the name of your domain, otherwise use ‘site’ instead of ‘sites’