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?

3
  • 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: stackoverflow.com/questions/16015548/… Commented May 7, 2015 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. Commented May 7, 2015 at 15:18
  • Paulpro, I've tried the same with POSTMAN. The results are still the same. Please find the edited question. Commented May 7, 2015 at 15:23

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This must be the selected answer. Remove headers and this will work just as said
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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.