Recently I came to face an unusual problem while posting a form. The form post works fine when there is no attachment or the attachment image file size is less than 100kb. But when I tried to upload a file larger than 100kb no element in the form is being posted/submitted. When I console.log()
the value it gives undefined. I can't understand what is causing the problem. No errors are shown on console screen. Can anyone help with this problem?
var name = req.param('name');
console.log(name);
The result i get is undefined
.
I'm using sails v0.10.5 on windows 8.1. I'm using postgres as my database.
Recently I came to face an unusual problem while posting a form. The form post works fine when there is no attachment or the attachment image file size is less than 100kb. But when I tried to upload a file larger than 100kb no element in the form is being posted/submitted. When I console.log()
the value it gives undefined. I can't understand what is causing the problem. No errors are shown on console screen. Can anyone help with this problem?
var name = req.param('name');
console.log(name);
The result i get is undefined
.
I'm using sails v0.10.5 on windows 8.1. I'm using postgres as my database.
Share Improve this question edited Apr 21, 2015 at 13:31 Travis Webb 15k9 gold badges57 silver badges110 bronze badges asked Apr 21, 2015 at 6:35 NakarmiNakarmi 4531 gold badge6 silver badges16 bronze badges 4-
Are you sure
req.param('name');
is returning a value? Also it has to be a string value so you could try to doname.toString();
– Bram Commented Apr 21, 2015 at 6:38 - no its not returning a value. Nothing from the form is being submitted when an attachment of size higher than 100kb is uploaded. console.log(req.param('name') also returns undefined. – Nakarmi Commented Apr 21, 2015 at 7:01
- Are you using FormData? – user4698813 Commented Apr 21, 2015 at 7:25
- I'm using enctype="multipart/form-data" – Nakarmi Commented Apr 21, 2015 at 7:39
5 Answers
Reset to default 9With skipper, you have to put all your inputs files at the end of the form. Otherwise it could bug-out.
had the same problem, turns out that the order of the inputs matter, says right here on the github skipper page
It is important to realize that the benefit above(Text Parameters) relies on a crucial, simplifying assumption: that user agents send any text parameters before the first file parameter in the multipart HTTP request body. For instance, in an HTML form that means putting all of your tags after the other inputs. If you don't want to lay your form out that way, you'll want to use AJAX to submit it instead
The req.param
method is used to get the url parameters, body parameters, and query parameters. (reference)
if you're using multipart/form-data
to upload files, Sails use skipper to parse the data, you can simply get the file like following
req.file('name').upload(function (err, uploadedFiles){
if (err) return res.send(500, err);
return res.send(200, uploadedFiles);
});
better use blueimp jquery file upload plugin.. it have multiple features it may help you.
I would suggest checking the official file upload documentation from sails....
http://sailsjs/#!/documentation/concepts/File-Uploads
I followed the steps and it works for me (on sails v 0.11). Perhaps you missed something along the way?