User Interface‎ > ‎

File Upload

This is an example of file upload. After uploading the file, it will appear in your document List.

Reference Page:http://code.google.com/googleapps/appsscript/class_fileupload.html

Example Demo:


Eaxmaple Code:
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);
  var app = UiApp.getActiveApplication();
  //Display a confirmation message
  var label = app.createLabel('file uploaded successfully');
  app.add(label);
  return app;
}
 
 



One Click File Upload
Example Demo:

Example Code:

function doGet(e) { 
  var app = UiApp.createApplication(); 
  var panel = app.createVerticalPanel().setId('panel');
  var fileUpload = app.createFileUpload().setName('theFile').setId('theFile');
  var handler = app.createServerChangeHandler('uploadfile');
  handler.addCallbackElement(panel);
  fileUpload.addChangeHandler(handler);
  panel.add(fileUpload);
  app.add(panel);
  return app;


function uploadfile(e) 

// data returned which can be used to create a blob
// assuming mime-type to be a zip file in this example
  var fileBlob = Utilities.newBlob(e.parameter.thefile, "application/zip","myZippedFile.zip" );
  var doc = DocsList.createFile(fileBlob);
  var app = UiApp.getActiveApplication();
  app.getElementById('panel').add(app.createLabel('File Uploaded successfully'));
  return app;
}
Comments