Jaseem Abbas
Jaseem Abbas

Reputation: 5230

Sails.js : File upload not working

I am developing a REST API in sails.js. I am trying to create an API which uploads images on to the server. This API is going to be called by my mobile device. My upload API is as follows.

upload: function (req, res) {

    res.setTimeout(0);

    req.file('avatar')
    .upload({

      // You can apply a file upload limit (in bytes)
      maxBytes: 1000000

    }, function whenDone(err, uploadedFiles) {
      if (err) return res.serverError(err);
      else return res.json({
        files: uploadedFiles,
        textParams: req.params.all()
      });
    });
}

I use POSTMAN to test my APIs. I call the API as follows

POSTMAN

My response says that there aren't any files uploaded. Where am I going wrong?

Upvotes: 2

Views: 1462

Answers (2)

Moises
Moises

Reputation: 53

Had the same issue and even used Advance REST client as suggested above. But after researching and almost submitting an issue in POSTMAN. My issue was that I was adding the custom header Content-Type: multipart/form-data AND selecting form-data it was interfering with the correct headers. If you select form-data, there is no need to set the custom header.

Upvotes: 2

Jaseem Abbas
Jaseem Abbas

Reputation: 5230

After hours of investigation I found that the problem was with POSTMAN and not with sails's skipper. I used Advanced REST client and it worked!

Upvotes: 1

Related Questions