I am trying to download an image to the client in my little node app. Here is my code:
app.post("/image-download", (req, res, next) => {
const image = path.join(__dirname, "/images", `/${req.body.imageName}`);
res.setHeader("Content-Type", "image/jpeg");
res.setHeader("Content-Disposition", "attachment");
res.send(image);
});
Where this image is stored in the path that I am constructing. I using fetch API on the front end and am able to receive the image and log it to the console, but how can I download it? Is this something that needs to be done on the front end? Thanks for the help!!
Edit: Just to clarify, what I want to mimic is the unsplash.com functionality. I want users to be able to download the images and this is my download route for their selected image.