I just deployed an PERN app on Heroku and during the sign-up process, I receive a 500 http error during the process of saving the image.
Router.post('/upload-image', (req, res) => {
try{
// validate if there is an image
if (req.files === null){
return res.status(201).json({
statusRequest: 'ok',
imagePath: '/uploads/img/avatar.png'
})
}
const image = req.files.file
image.mv(`../../build/uploads/img/${image.name}`, error => {
if (error) {
return res.status(500).json({
statusRequest: 'failed',
errorInfo: 'Hubo un problema. Vuelve a intentarlo.'
})
}
return res.status(201).json({
statusRequest: 'ok',
imagePath: `/uploads/img/${image.name}`
})
})
}catch (error) {
return res.status(400).json({
statusRequest: 'failed',
errorInfo: 'Hubo un problema. Vuelve a intentarlo.'
})
}
})