i have html form makes post request /upload/upld in sails app. aim have 2 parameters: photo uploaded , location photo taken. upload controller supposed upload file directory value of location parameter.
<form method="post" action="/upload/upld" enctype="multipart/form-data"> <span class="btn btn-default btn-file wow bouncein top-buffer"> browse <input type="file" name="photo"> <input type="hidden" name="location" value="istana" /> </span> <input type="submit" class="btn btn-primary wow bouncein top-buffer"> </form> unfortunately code not seem working. output on console shows following whenever upload single file. i'm not sure why upld method seems run twice on single upload.
{ location: 'istana', id: undefined } istana { id: undefined } undefined my upload controller looks this:
upld: function (req, res) { var params = req.params.all(); console.log(params); var this_location = params.location; console.log(this_location); req.file('photo').upload({ dirname:require('path').join('./',this_location)},function (err, files) { if (err){ return res.servererror(err); } return res.view('homepage',{ message: files.length + ' file(s) uploaded successfully!', files: files } ); }); }
i found problem in how structured form. due way sails uses skipper handle multipart/form-data, had move file input after hidden text field.
Comments
Post a Comment