2

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?

Jaseem Abbas
  • 5,028
  • 6
  • 48
  • 73
  • When you upload a file, the whole file is sent, not just the file name. I'm not sure if there is a way to do it or not in DHC, but you can in Postman. See the answer here: http://stackoverflow.com/questions/16015548/tool-for-sending-multipart-form-data-request – Paul May 07 '15 at 15:17
  • btw, why is your title "Install Node.js 0.10.36 on Amazon Linux"? That doesn't seem related to your question. – Paul May 07 '15 at 15:18
  • Paulpro, I've tried the same with POSTMAN. The results are still the same. Please find the edited question. – Jaseem Abbas May 07 '15 at 15:23

2 Answers2

2

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.

Moises
  • 53
  • 1
  • 6
1

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!

Jaseem Abbas
  • 5,028
  • 6
  • 48
  • 73