I wanted to add new fields (objects) other than multer-gridfs-storage default fields but to no avail, the fields i want to add are:
- Description
- category
- Token
The default field has something like
- _id
- length
- chunksize
- uploadDate
- md5
- contentType
instead want to add something like
- _id
- length
- chunksize
- uploadDate
- md5
- contentType
- description
- category and the rest
And also is there a way to add a thumbnail to file so i don't i have reference my file id to the thumbnail in other collection
const storage = new GridFsStorage({
url: config.db,
file: (req, file) => {
return new Promise((resolve, reject) => {
const filename = req.body.fileName + path.extname(file.originalname);
const Description = req.body.Description
const fileInfo = {
filename: filename,
bucketName: 'contents',
metadata: req.body,
}
resolve(fileInfo, Description);
});
}
});
const upload = multer({
storage
});
router.get('/', (req, res) => {
res.render('index');
console.log(req.body)
});
//** uploading file to the db */
router.post('/', upload.any(), (req, res) => {
res.redirect('/upload/files')
});