projeto-hit/TEST_SERVER1/test/whats/helpers/image-uploader.js

36 lines
914 B
JavaScript

const multer = require('multer')
const path = require('path')
//Destination to store the images
const imageStorage = multer.diskStorage({
destination: function(req, file, cb){
// let folder = ""
// if(req.baseUrl.includes("users")){
// folder = "users"
// }else if(req.baseUrl.includes("pets")){
// folder = "pets"
// }
cb(null, path.join(process.cwd(),'medias', 'out'))
},
filename: function(req, file, cb) {
cb(null, Date.now() + path.extname(file.originalname))
}
})
const imageUpload = multer({
storage: imageStorage,
// fileFilter(req, file, cb){
// if (!file.originalname.match(/\.(jpg|jpeg|png)$/)){
// return cb(new Error('Por favor, envie apenas jpg ou png!'))
// }
// cb(undefined, true)
// }
})
module.exports = { imageUpload }