skip to Main Content

I want to store image link in mongo db by not converting image to base64 and on deployment new pictures can be added to database, i cannot do it solely by using mongo db. I try using multer package but on deployment new uploaded image is not showing and base64 is too long string i dont want to store it against an image

2

Answers


  1. Chosen as BEST ANSWER

    There is no way to store images in mongodb directly that will also be added after deployment except by converting image into base64 which will give too long string and not efficient to store in database, you first have to upload your image to a cloud storage e.g, firebase from which you get the link of your image then you can store this link in database, now in this way after deployment you can add more images to mongodb.


  2. Multer should be the way to do it, il save file on server storage (your hard drive) and return the path of file. Then you can save that path to mongo as string.

    In a second way, you have to reach the file from a request (i guess with nodejs?) using static routing.

    With express you can achive that by adding

    app.use(express.static('public'));
    

    with ‘public’ the folder where files are stored

    Then any request like http://example.com/public/file.png should render the file if it exists.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search