router.post( '/image', authenticate, multer({ storage: multerS3({ s3, metadata(req, file, cb) { cb(null, { originalname: file.originalname, }); }, bucket: `${process.env.DO_BUCKET}/somoy-backend-api-blob/images`, contentType: multerS3.AUTO_CONTENT_TYPE, acl: 'public-read', key(req, file, cb) { const extension = file.originalname.split('.').pop(); if (!imageFormats.includes(extension)) { const err = new Error('Invalid Image Format'); err.status = 400; throw err; } const filename = `${crypto.randomBytes(24).toString('hex')}.${extension}`; cb(null, filename); }, }), }).array('images'), async (req, res, next) => { // const imageTags = req.body.tags.length > 0 ? req.body.tags.split(',') : []; if (req.files.length > 0) { req.files.forEach((file, i) => { req.files[i].location = `${process.env.CLOUDFRONT_IMAGE_URL}/${file.key}`; // req.files[i].tags = imageTags; }); // await Image.insertMany(req.files); } try { res.status(200).json({ status: 'success', message: 'Files Uploaded!', data: { images: req.files, }, }); } catch (err) { next(err); } }, );