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

126
Views
Send a file through AJAX with symfony

I am trying to send a CSV file with an AJAX request en then handle it in a controller. My problem is I am getting a null file in my controller.

Here is my AJAX request :

let csvfile = csvFile.files[0]
var data = new FormData();

data.append('file', csvfile)
// console.log(...data)
$.ajax({
    type        :   'POST',
    url         :   '/template/generateAuto/' + templateId,
    contentType: false,
    processData : false,
    data: data,
    success: function(msg) {console.log(msg)},
});

Here is my controller function that should handle the file

$file = $request->files->get('file');
return new JsonResponse($file);

I here am just trying to debug that's why there's only this part of code in my controller.

I tried dumping the $request in my controller but I have nothing.

I have already looked at this similar question but I can't find what I am doing wrong. Since I tried dumping my $requestand it is empty. Also, doing a console.log(...data) outputs this :

0 "file"
1 File {name: "template74.csv", lastModified: 1651136688000, webkitRelativePath: "", size: 200, type: "text/csv", …}

So my file is in my FormData.

about 4 years ago · Juan Pablo Isaza
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!