Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
Parse files in FileList object

I am using FormData to upload multiple files in my grails project.The files needs to be uploaded via Ajax. I have used following code for ajax upload. But in controller, I get the params as [object FileList]. How do I get files from this object. Is there any way to change this object to multipart?

jQuery('#file-save').click(function() {
  if (jQuery('#form input[type="file"]')) {
    var form = jQuery("#form").find('input[type="file"]');

    var picData = new FormData();
    picData.append('userFiles', form.get(0).files);
    picData.append('userId', '$usrId');

    jQuery.ajax({
      url: '/file/upload',
      type: 'post',
      dataType:'json',
      data: picData,
      enctype: "multipart/form-data",
      contentType: false,
      processData: false,
      success: function(data) {
        console.log("success");
      }
    });
  }
});
The controller code is:

def upload(){
    def userId = params.userId
    def inputFile = params.userFiles
    println(inputFile)
    inputFile.each{i,j->
        println(i)
        println(j)
    }
}

When I debug, I get params.userFiles : "[object FileList]". Any insights would be appreciated.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You most likely need to loop through the files client side, adding the same key for each one

var picData = new FormData();
// loop through form.get(0).files
picData.append('userFiles', file);
// end loop
picData.append('userId', '$usrId');
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!