File upload from file-based module Assay

LabKey Support Forum (Inactive)
File upload from file-based module Assay Anthony Corbett  2013-03-20 08:15
Status: Closed
 
I'm having issues uploading a file from a file-based module assay. I've looked that the suggested examples from https://www.labkey.org/wiki/home/Documentation/page.view?name=moduleassay.

In all the upload.html files that do file uploads they use a version of the following HTML and Ext Javascript:

<form id="upload_form" enctype="multipart/form-data" method="POST">
   <div id="fileUploadField"></div>
</form>

<script type="text/javascript">
var expData;

Ext.onReady(function () {
    
    function handleNewFileUpload(form, action) {
       if (action && action.result && action.result.id) {
          expData = new LABKEY.Exp.Data(action.result);
       }
    }

    var form = new Ext.form.BasicForm(
      Ext.get("upload_form"), {
      fileUpload: true,
      frame: false,
      url: LABKEY.ActionURL.buildURL('assay', 'assayFileUpload'),
      listeners: {
        "actioncomplete": function (f, action) {
          handleNewFileUpload(f, action);
        },
        "actionfailed": function (f, action) {
          handleNewFileUpload(f, action);
        }
      }
    });

    new Ext.form.FileUploadField({
      renderTo: "fileUploadField",
      buttonText: "Upload New File...",
      buttonOnly: true,
      buttonCfg: {
        cls: "labkey-button"
      },
      listeners: {
        "fileselected": function (fb, v) {
          form.submit();
        }
      }
    });
})
</script>

When I look at firebug for the response from the POST to AssayController's assayFileUpload Action the response (action.result) looks like this:

 { success: true }

There is no id attribute of the ExpData created on the server in the response.

When I attach a debugger on the server in AbstractFileUploadAction.export(), the FileUploadForm instance does not have a fileName or fileContent. Maybe the parameters aren't being bound correctly to this bean?

I'm using Firefox 19 and Tomcat 6.0.35 locally, could there be a Tomcat specific configuration issue here?

Thanks,

Anthony Corbett
 
 
Anthony Corbett responded:  2013-03-20 13:22

I've looked into this a bit further:

In SpringActionController.handleRequest() it is correctly detecting the multipart and resolving the request to Spring's DefaultMultipartHttpServletRequest. However its private multipartFiles Map is empty.

This leads to the iterator not having any fileNames to iterate over in AbstactFileUploadAction.export()


Not sure how to proceed. Any help would be greatly appreciated.
 
Anthony Corbett responded:  2013-03-21 10:52

I have got this working. I ended up comparing two different upload.html implementations using FileUploadField.js in two different file based assays. The differences I saw, (1) the id of the form and div were different and (2) they were calling LABKEY.requiresScript('FileUploadField.js') AFTER their HTML markup, were I was doing it at the top of my page. Either one of those 2 things fixed my issue. I'm thinking changing the id of the elements had no impact (as long I was referencing them correctly in my BasicForm and FileUploadField code).

Would it be possible to change the action's response to not be successful if no files were actually created on the server? In my case it was posting a multipart/form-data but there were no files sent and the filesNames iterator had nothing to do.


Regards,

Anthony
 
kevink responded:  2013-03-22 10:14
Thanks for the information Anthony.

I've filed a bug to return an error if the file upload was not successful:
https://www.labkey.org/issues/home/Developer/issues/details.view?issueId=17462