没有FormPanel的Google Apps脚本FileUpload()? [英] Google Apps Script FileUpload() without FormPanel?

查看:133
本文介绍了没有FormPanel的Google Apps脚本FileUpload()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建我的第一个使用Google Apps脚本的应用程序。我需要一个允许上传文件到Google文档列表的表单。我目前使用的代码基于 Google Apps脚本FileUpload文档: / p>

 函数doGet(e){
var app = UiApp.createApplication()。setTitle(Upload CSV to Sheet );
var form = app.createFormPanel()。setId('frm')。setEncoding('multipart / form-data');
var formContent = app.createVerticalPanel();
form.add(formContent);
formContent.add(app.createFileUpload()。setName('thefile'));
formContent.add(app.createSubmitButton('Submit'));
app.add(form);
返回应用程序;


函数doPost(e){
//返回的数据是FileUpload小部件的一个blob
var fileBlob = e.parameter.thefile;
var doc = DocsList.createFile(fileBlob);
app.close();
返回应用程序;

$ / code>

但是,我想为Submit按钮指定我自己的点击处理程序,如果可能,不要等待POST。当我试图把上面的代码改成这样的东西时,对 e.parameter.thefile 的引用是null,并且不包含文件blob。

 函数doGet(e){

var app = UiApp.createApplication()。setTitle(Upload CSV to Sheet)
var formContent = app.createVerticalPanel();
var submitServerHandler = app.createServerClickHandler('submitHandler_');
formContent.add(app.createFileUpload()。setName('thefile'));
submitServerHandler.addCallbackElement(formContent);
formContent.add(app.createButton('Submit')。addClickHandler(submitServerHandler));
app.add(formContent);
返回应用程序;


函数submitHandler_(e){
//返回的数据是FileUpload小部件的一个blob
var fileBlob = e.parameter.thefile;
var doc = DocsList.createFile(fileBlob);
app.close();
返回应用程序;



$ b $ p $是否有可能在没有FormPanel的情况下使用FileUpload控件?如果是这样,怎么样?谢谢!

解决方案

您必须使用doPost才能使文件上传正常工作。您可以添加更多点击处理程序到提交按钮。如果你想在UI上做出快速响应,可以使用客户端处理程序。任何你在名为表单面板上的东西都会在e.parameter中传递,你可以像普通的HTML表单一样使用hiddens。

你想要做什么?这会帮助我给你一个更好的答案。

I am in the process of building my first application that makes use of Google Apps Script. I need to have a form that allows the upload of a file to a Google Documents List. I currently have this working using code based on the Google Apps Script FileUpload docmentation :

function doGet(e) { 
  var app = UiApp.createApplication().setTitle("Upload CSV to Sheet");
  var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
  var formContent = app.createVerticalPanel();
  form.add(formContent);  
  formContent.add(app.createFileUpload().setName('thefile'));
  formContent.add(app.createSubmitButton('Submit'));
  app.add(form);
  return app;
}

function doPost(e) {
  // data returned is a blob for FileUpload widget
  var fileBlob = e.parameter.thefile;
  var doc = DocsList.createFile(fileBlob);
  app.close();
  return app;
}

However, I would like to specify my own click handlers for the Submit button and not wait for the POST if possible. When I tried to change the code above to something like this, the reference to e.parameter.thefile is null and does not contain the file blob.

function doGet(e) {

  var app = UiApp.createApplication().setTitle("Upload CSV to Sheet");
  var formContent = app.createVerticalPanel(); 
  var submitServerHandler = app.createServerClickHandler('submitHandler_');
  formContent.add(app.createFileUpload().setName('thefile'));
  submitServerHandler.addCallbackElement(formContent);  
  formContent.add(app.createButton('Submit').addClickHandler(submitServerHandler));  
  app.add(formContent);
  return app;
}

function submitHandler_(e) {
  // data returned is a blob for FileUpload widget
  var fileBlob = e.parameter.thefile;
  var doc = DocsList.createFile(fileBlob);
  app.close();
  return app;
}

Is it possible to use the FileUpload control without a FormPanel? If so, how? Thanks!

解决方案

You must use doPost for the file upload to work. You can add more click handlers to the submit button. If you want a fast response on the UI use a client side handler. Anything you have on the form panel that is named will be passed in e.parameter and you can use hiddens like in a normal html form.

What is it that you want to do? That would help me give you a better answer.

这篇关于没有FormPanel的Google Apps脚本FileUpload()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆