这些是我得到的错误:
[13-12-23 22:43:26:376 EST]页面类型:FileCabinetPage
[13-12-23 22:43:26:376 EST]文件blob:undefined
[13-12-23 22:43:26:383 EST]错误消息:无法找到方法addHostedAttachment((class))。
以下是我的代码摘录:
function doGet(){
var app = UiApp.createApplication().setTitle("Shipping Label Request Form");
var form = UiApp.createFormPanel();
var panel = UiApp.createVerticalPanel();
var attachment = app.createFileUpload().setId('attachment').setName('attachment')
var button = app.createSubmitButton('Submit').setId("button");
app.add(form);
form.add(panel);
panel.add(attachment);
panel.add(button);
// not needed with formPanel //
// var handler = app.createServerHandler('submitAnnouncement');
// button.addClickHandler(handler); //
return app;
}
// submitAnnouncement changed to doPost()
function doPost(e) {
var app = UiApp.getActiveApplication();
var page = SitesApp.getPageByUrl('https://sites.google.com/...')
var fileBlob = e.parameter.attachment;
Logger.log('Page type:' +page)
Logger.log('File blob:' +fileBlob)
try {
page.addHostedAttachment(fileBlob)
}
catch(e){
Logger.log('Hosted attachment error msg:' +e.message);
}
}
答案 0 :(得分:1)
代码中的服务器处理程序无法使用参数附件,为了解决此问题,您可以使用
var handler = app.createServerHandler('submitAnnouncement')addCallbackElement(attachment)
或者您可以将附件和按钮封装在垂直面板中,然后必须将其放入表单面板中,您的代码才能开始工作。