I uploaded my image using multer middleware
const storage = multer.diskStorage({
destination: function(req, file, cb) {
// fs.mkdir('../uploads/', (err) => {
cb(null, './public/images/')
// console.log(err)
},
filename: function(req, file, cb) {
cb(null, `${Date.now()}-hemmyhtec-${file.originalname}`)
}
})
const fileFilter = (req, file, cb) => {
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png') {
cb(null, true)
} else {
cb(null, false)
const error = new Error('Wrong File, only image are allowed')
console.log(error)
}
}
My Image got saved into the folder and name into the database as file: ("1632760261507-hemmyhtec-1.png").
So when ever I fetch my data alongside with the file name in my database I got this below
It added "\" at the beginning \"" and also at the end of the file name.
Which gives me an error while fetching in my vuejs code
Can anyone tell me the Problem or a better way to do it?
Code for creating the file...
const file = req.file;
MentorProfile.create({
file: file.filename,
profession: req.body.profession,
about: req.body.about.....
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment