Closed jsrosas closed 9 years ago
Hi, I don't know multer, but if you can provide a test for your issue, i'ld be happy to look into it.
Thanks a lot Reggiino. My code to recieve from form post is like this. But the form also contains 5 more images. RIght now I am saving each image by creating a new writestream and giving it the req.file.file.path. Is there a better solution? When I use something like mongovue it only shows one image then the rest of the images give me errors. But I do see them saved on mongo as files each with correct information and metadata. I am doing this with express, multer, mongoose. Is this the right way to do it? Like I mentioned mongovue can only display one image the rest of them give me errors.
app.post('/new',function(req,res){
console.log(req.body);
console.log(req.files);
var taxi = new taxiModel.Taxi({
firstname:req.body.firstname,
lastname:req.body.lastname,
tel:req.body.tel,
company:req.body.company,
dni:req.body.dni,
dnidate:req.body.dnidate,
license:req.body.license,
licensedate:req.body.licensedate
});
taxi.save(function(err){
console.log(err);
var path1 = req.files.avatar.path;
var gfs = Grid(conn.db);
//here i start doing the stream per each image.
var writestreamAvatar = gfs.createWriteStream({
filename : req.body.dni,
//metadata : {type:'avatar'}
});
fs.createReadStream(req.files.front.path).pipe(writestreamFront);
//this is the stream for the second img and so on.
var writestreamDnifront = gfs.createWriteStream({
filename : req.body.dni,
//metadata : {type:'dnifront'}
});
fs.createReadStream(req.files.dnifront.path).pipe(writestreamDnifront);
Do i have to create a stream for each image? var writestream 1 then pipe that, then var wraitestream2 and s on?
Yes.
And as far as i can quickly see, this looks pretty correct. If you have any other errors or issues, please let us know.
Hi I cannot figure out how to pass multiple files from one form. I am using multer. And the output from multer after processing the form is
Do i have to create a stream for each image? var writestream 1 then pipe that, then var wraitestream2 and s on?