Isilmë O.
Isilmë O.

Reputation: 1746

SailsJS: POST requests are not resolved properly when invoking req.param() and req.file()

I use PostMan to test my controller, which reads data from the POST request by using req.param() and req.file(). Weirdly, the order of the parameters I submit matters. For example,

Case 1:

file: some file attached
property1: 1

The file would be resolved properly while property1 wouldn't (undefined).

Case 2:

file: some file attached
property1: 1
property2: 2

req.param('property2') would return 1 (yes, 1, no typo here) for the first requests and undefined for the subsequent ones.

Case 3:

property1: 1
file: some file attached

This way, everything works fine.

Is it an expected behavior or a bug? Thx in advance.

Upvotes: 2

Views: 533

Answers (2)

particlebanana
particlebanana

Reputation: 2416

With Skipper (the file upload system in Sails) you need to send all of your text parameters before the file parameter. Case three in your examples should be how you always send the request. For more information see the Skipper Docs:

https://github.com/balderdashy/skipper#text-parameters

Upvotes: 3

Xinzz
Xinzz

Reputation: 2242

req.param() is for PATH parameters. I'm guessing you are trying to get post data here, so you should be using req.body('key').

Upvotes: 0

Related Questions