Sorry, still new at nodejs. So I decided to use:
app.get("/api/image/:filename", async (req, res) => {
const { filename } = req.params;
pool.query("SELECT * FROM image_files WHERE id = $1", [filename])
.then(images => {
if (images[0]) {
const dirname = path.resolve();
const fullfilepath = path.join(dirname, images[0].filepath);
return res.type(images[0].mimetype).sendFile(fullfilepath);
}
return Promise.reject(new Error('Image does not exist'));
})
.catch(err => res.status(404).json({success: false, message: 'not found', stack: err.stack}),
);
});
my uploads live in the backend folder of ‘server>uploads>(images)’
<img src="yourdomain.com/[path-to-image]" />
This would get the image directly from the folder, and not as I upload right?
Thanks for letting me know the problem!