Penyimpanan Multer Gridfs
all you need is here! \m/
conn.once('open', ()=> {
//Init stream
let gfs = Grid(conn.db, mongoose.mongo);
gfs.collection('uploads');
})
// creating storage engine
var storage = new GridFsStorage({
url: URI,
file: (req, file) => {
return new Promise((resolve, reject) => {
crypto.randomBytes(16, (err, buf) => {
if (err) {
return reject(err);
}
const filename = buf.toString('hex') + path.extname(file.originalname);
const fileInfo = {
filename: filename,
bucketName: 'uploads'
};
resolve(fileInfo);
});
});
}
});
const upload = multer({ storage }); //upload is working as a middleware here!
Aryamitra Chaudhuri