const { Router } = require('express')
const multer = require('multer')
const router = router
const storage = multer.memoryStorage()
const upload = multer({ storage: storage})
const func = async (req, res) => {
console.log(typeof req.file) // buffer
console.log(typeof req.file.buffer)
// send image back
if (req.file.memetype === 'image/jpg'){
res.set('Content-Type', 'image/jpg')
res.send(req.file.buffer)
} else {
res.send('it is not image')
}
}
router.route('/upload')
.post(upload.single('file'), func)