Search code examples
node.jsexpresshttpmulter

where to save images uploaded via POST and how to send that image via GET


My problem seems common but with a variety of use cases, I couldn't find the exact answer

the idea:

user will upload an image from front-end, every upload should create a json entry in database like:

{
    id: number,
    description: string,
    image_url: string //important, this should be the image url
}

where do I save these images such that I can have an image_url so whenever someone puts the url in browser that image is seen


Solution

  • You can save your images in a folder and then serve its files using something like this:

    app.use('/images', express.static('images'))
    

    and image links would be like your-domain.com/images/IMAGE_NAME. you can read more here