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
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.
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
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.