×
We value your feedback! Please click here to access our 2024 Client Survey.
The survey will remain open until November 1st. Your perspective will help guide our product/service planning and goals for the upcoming year and beyond!

How can I create a custom mapping that accepts MultipartFile?

LabKey Support Forum
How can I create a custom mapping that accepts MultipartFile? kevink  2015-04-16 11:08
Status: Closed
 
First, we have a few JavaScript APIs that you can try using to POST a file and get back a JSON formatted response. It requires two round-trips: 1) POST the file to assay/assayFileUpload.view to create an ExpData object, (2) create a LABKEY.Exp.Data from the response and call data.getContent() to parse the Excel file into JSON.

See the example in:
https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.Exp.Data.html

Second, to answer the question about getting a POSTed file: within your Java action call .getFileMap() -- for example:

    @RequiresPermissionClass(InsertPermission.class)
    public class ConvertXlsToJsonAction extends ApiAction
    {
        @Override
        public Object execute(Object o, BindException errors) throws Exception
        {
            Map<String, MultipartFile> files = getFileMap();

            List<String> names = new ArrayList<>();
            for (MultipartFile file : files.values())
                names.add(file.getOriginalFilename());

            JSONObject json = new JSONObject();
            json.put("fileNames", names);
            return json;
        }
    }