I have an html form that makes a POST request for /upload/upldin my sails application. My goal is to have two options: the uploaded photo and the place where the photo was taken. My download controller should upload the file to a directory with the location parameter value.
<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, this code does not work. The console output shows the following when I upload only one file. I am not sure why the upld method works twice in the same load.
{ location: 'istana', id: undefined }
istana
{ id: undefined }
undefined
My boot controller is as follows:
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
}
);
});
}
source
share