0
I’m having some difficulty with Javascript and Nodejs. I’m new to them. I made an application in React Native and the person can choose to delete their profile image. There are also images in the ads section. I would like to delete the images before uploading the new ones, as the user can choose not to use images in the future. I’m using Multer for uploads and Fs.unlink to delete the images. But I’m not sure where to fit Fs.unlink to delete them before, whether it’s inside the woman herself or have to create a middleware, I have no idea...
const deleteFile = (filePath) => {
fs.unlink(filePath, (error) => {
if (!error) {
console.log(false);
} else {
console.log('Erro ao deletar arquivo.');
}
})};
const StoragePerfil = multer.diskStorage({
destination(req, file, callback) {
callback(null, './assets/upload/perfil');
},
filename: (req, file, callback) => {
callback(null, `${file.originalname}`)
},
});
const uploadPerfil = multer({ storage: StoragePerfil });
app.put('/user/perfil/:id_user', authMiddleware.checkAuth, uploadPerfil.array('photo', 3), perfilController.updatePerfil);