0

I try to create a web application (on google site) which uses google-apps-script to read data from standard .txt files. I succeed with the following code which uses FileUpload widget and wants me to chose the file.

function doGet() {
  var app = UiApp.createApplication();

  var form = app.createFormPanel().setId('form').setEncoding('multipart/form-data');
  app.add(form);

  var formContent = app.createGrid().resize(2,2);
  form.add(formContent);

  formContent.setWidget(0, 0, app.createLabel('File:'));
  var fileUpload = app.createFileUpload().setName('thefile').setId('fileID');
  formContent.setWidget(0, 1, fileUpload);
  formContent.setWidget(1, 1, app.createSubmitButton('Submit'));

  return app;
}

function doPost(e) {
  var fileBlob = e.parameter.thefile;
  var app = UiApp.getActiveApplication();
  var metin = fileBlob.getDataAsString();
  var dataAsByte = fileBlob.getBytes();  
  var stringArray = metin.split('\n');

  return app;
}

But, what I need is to process several .txt files and collect the data. Hence this 'fileUpload widget' is not what I want. I want to give a list of file paths from my local disc, and process each file, of which the path is given by the list, successively.

So the method to fill the fileBlob using file paths would be the answer for me!

Thanks.

1
  • Class UiApp was deprecated. Commented Nov 6, 2016 at 15:03

1 Answer 1

1

You can add multiple file upload widgets to the same form. Unfortunately you can't upload an entire path.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Corey, but I don't want to use the widgets and pick the files each time. I want to use paths to start the process. At the end, that widget should have been using the path inside its code I guess; but I couldn't find it yet!
It can't be done with browser file widgets, which is all you can use in UiApp.
You can make a zip file on your computer, upload the zip file instead of the individual text files, and use Utilities.unzip to get the individual files. That's the closest you can come to making this work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.