I am using express to store images, using markdown.
I use multer on backend to store Images on backend on a folder called ‘uploads’.
In the controller, I build the URL referred to the image, and push it into a model array.
const imageURL = `${req.protocol}://${req.get('host')}/uploads/${req.file.filename}`;
The result would be :
- Production : https://blog-server-bae4.onrender.com/uploads/1714303937397.jpg
- Development : http://localhost:3000/api/uploads/1714303937397.jpg
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
On frontend, after uploading the image to the server, I get back the link specified. If I access it within local development, I get the image with no problems. But when I access it over production, I get invalid URL, because I have the Not found express router.
{
"message": "The url you provided does not exists"
}
On the network tab in the chrome inspector I have 404 error.