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

184
Views
How to configure API endpoint to receive file from ember-uploader component

I'm trying to figure out how to use ember-uploader, I have the following component (like the one in the README)

export default EmberUploader.FileField.extend({
  filesDidChange: function(files) {
    const uploader = EmberUploader.Uploader.create({
      url: (ENV.APP.API_HOST || '') + '/api/v1/images/',
    });
    console.log(uploader);

    if (!Ember.isEmpty(files)) {
      var photo = files[0];
      console.log(photo);

      uploader.upload(photo)
        .then(data => {
          // Handle success
          console.log("Success uploading file");
          console.log(data);
        }, error => {
          // Handle failure
          console.log("ERROR uploading file");
          console.log(error);
        });
    }
  }
});

The express API endpoint is listening for a POST request.

var saveImage = (req, res, next) => {
    let body = req.body;
    res.json({
      data: body
    });
};

But the body is empty after the request is done. I really don't know how to implement the API endpoint in order to get the file, I tried to see the req object and it doesn't contains the file.

Debugging it, After select a file using the component I get the following info in the console.

js console

Seems that the API endpoint works because I get the following output:

POST /api/v1/images/ 200 27.284 ms - 11

But I can't get the file.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

SOLUTION

In Express 4, req.files is no longer available on the req object by default. To access uploaded files on the req.files object, use a multipart-handling middleware like busboy, multer, formidable, multiparty, connect-multiparty, or pez.

Following this blog, the code below was added to the API and the ember-uploader code posted in the question worked as expected.

import formidable from 'formidable';

var saveImage = (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req);

    form.on('fileBegin', function (name, file){
        file.path = __dirname + '/tmp/' + file.name;
    });

    form.on('file', function (name, file){
        res.json({
            data: file.name
        });           
    });
};
about 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!