четверг, 12 мая 2011 г.

A FileUpload control

FileUpload returns blob which can we used in various other functions. Below is an example of how to use FileUpload.

http://code.google.com/intl/ru/googleapps/appsscript/service_ui.html

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 which can be used to create a blob
 
var assignmentFile = e.parameter.file;
 
// create a blob which mime type of the document.
 
// assuming mime-type to be text in this example
 
var uploadBlob = Utilities.newBlob(assignmentFile, "text/plain", "Filename.txt" );
 
Logger.log("Size:"+uploadBlob.getBytes().length);
 
// only applicable for Google Apps accounts
 
var doc = DocsList.createFile(uploadBlob);
  app
.close();
 
return app;
}

Комментариев нет:

Отправить комментарий