Search code examples
google-apps-scriptfile-uploadweb-applicationsgoogle-drive-api

File Upload, Submit Button and doPost issue


There is something I do not understand with the Apps Script GUI Builder.
I am trying to have a File Upload and I cannot have it working.
Basic setup: form panel, a flow panel, a file upload, a submit button.
I did not put any Events on On Mouse Click (I understood that the doPost catch it by default).

The associated functions:

function appBVFileUpload2() {
   var mydoc = SpreadsheetApp.getActiveSpreadsheet();  
   var app = UiApp.createApplication().setTitle('File Upload');
   app.add(app.loadComponent("ImportationBV")); // load the GUI
   mydoc.show(app); 
}

function doPost(e) {
  // data returned is a blob for FileUpload Form
  var fileBlob = e.parameter.thefile; // thefile is the name of the File Upload Object
  var doc = DocsList.createFile(fileBlob); // Generate the Error <<<
  var app = UiApp.getActiveApplication();
  app.close();
  return app; 
}

So I always get an error when clicking on the submit button:

Error encountered: An unexpected error occurred

Important note: the error is generated by the line var doc = DocsList.createFile(fileBlob); . So I suspect either the data from the file upload object is not received properly.

Interestingly enough the example provided by Google here works for me. Meaning that if the GUI is done via code and not via the GUI builder the upload works.

I triple checked everything, I am really puzzled, and start to think there may be a bug with the File Upload via the GUI Builder. Any help?


Solution

  • This error comes often when the name of the widget is not what it should be, you could try to log the e.parameter to see what is in it...Logger.log(e.parameter); Check also that the widget's name has no accidental space in it...

    EDIT : following your comments, I tested it here and it works. Could you please check if you have the same setup (component tree, names...) , here is a screen cap. : enter image description here