Next: File upload with google script

File upload with google script


 function doGet(e) {  
  var app = UiApp.createApplication().setTitle('File Upload');  
  var infoBox = app.createLabel().setVisible(false).setId('infoBox');  
  app.add(infoBox);  
  //Form panel is required for upload  
  var form = app.createFormPanel().setId('form').setEncoding('multipart/form-data');  
  app.add(form);  
  //a grid to hold the widgets to guild user  
  var formContent = app.createGrid().resize(4,2);  
  form.add(formContent);  
  //create a text box to name the file  
  formContent.setText(0, 0, 'File Name: ')  
  formContent.setWidget(0, 1, app.createTextBox().setName('newName'));  
  //create file upload widget  
  formContent.setWidget(1, 0, app.createLabel('File:'));  
  fileUploadBox = app.createFileUpload().setName("file");    
  formContent.setWidget(1, 1, fileUploadBox);  
  //create submit button   
  formContent.setWidget(2, 1, app.createSubmitButton('Upload'));  
  return app;  
 }  
 function doPost(e){  
  var app = UiApp.getActiveApplication();  
  //creates the file in Docs  
  var file = DocsList.createFile(e.parameter.file);  
  file.rename(e.parameter.newName);  
  //notify user of success   
  app.getElementById('infoBox').setText('Upload Complete').setVisible(true);  
  return app;  
 }