aheckmann / gridfs-stream

Easily stream files to and from MongoDB
MIT License
615 stars 120 forks source link

multi upload to mongodb #101

Open kkkm opened 7 years ago

kkkm commented 7 years ago
app.post("/", upload.single("avatar"), function(req, res, next){
    var writestream = gfs.createWriteStream({
     filename: req.file.filename
    });
 fs.createReadStream( "./uploads/+ req.file.filename)
   .on("end", function(){fs.unlink("./uploads/+ req.file.filename, 
function(err){res.send("success")})})
  .pipe(writestream);
   });

I want to upload 2 images from temp folder to mongodb,

I can create write and read streams for one image but lost idea for two files. I can pipe for one image but not two. When I try array medthod, it replys "TypeError: Cannot read property 'filename' of undefined" ERROR. My goal is to upload two files to mongodb in one method or what ever at once.

How can I have done ?