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.
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:
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')
.