assayFileUpload: larger file from JS variable

LabKey Support Forum
assayFileUpload: larger file from JS variable Tim Holland  2018-08-01 08:12
Status: Closed
 

Hi,

I'm attempting to use LABKEY.Ajax.request to create an assay file with assayFileUpload using the contents of a Javascript variable, but when the fileContents parameter gets too big (even just on the order of a few hundred lines) the request fails. It uses the method described in the documentation here: https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.Exp.Data.html, with something like the following:

LABKEY.Ajax.request({
    url: LABKEY.ActionURL.buildURL("assay", "assayFileUpload", LABKEY.ActionURL.getContainer()),
    params: { protocolId: assay.id, fileName: name, fileContent: lines },
    success: function(response) {
        // ...do something...
    },
    failure: formFailed
});

Is there a recommended way to create a larger file from the contents of a Javascript variable that gets around this limitation? I'd prefer not to have to edit the Tomcat configuration files to do this.

 
 
kevink responded:  2018-08-02 10:03

You can use a multipart form post instead. You can create a file using the string contents:

var form = window.FormData();
form.set('fileName', 'foo.txt');
form.set('fileContent', '...');

LABKEY.Ajax.request({
    url: LABKEY.ActionURL.buildURL("assay", "assayFileUpload", null, { protocolId: assay.id }),
    form: form
});

Or you can let the user upload a file using a file input:

<form id='myform'>
  <input name='myfile' type='file'>
</form>
<button onclick='uploadMe();return false;'>Upload</button>

<script>
function uploadMe()
{
  var form = document.getElementById('myform');
  LABKEY.Ajax.request({
    url: LABKEY.ActionURL.buildURL("assay", "assayFileUpload", null, {protocolId: assay.id }),
    form: form
  });
}
</scrit>