Home > Blockchain >  How to use a image URL in mongodb database
How to use a image URL in mongodb database

Time:09-27

I want to bring up a website that is a cosmetics project. and I want to create product info for them each product has an image that I make a URL for them and I want to use an ejs for them. ex: for a product for its image I want to write <%= product.img %> and the product image will show up and I don't know how to put a URL in the MongoDB database to when I type the ejs in .ejs file it will show up the image of the product. I search a lot in google all of them was for that user to upload an image on the website but I want to upload an image in my database and then use it with ejs file.

CodePudding user response:

just store the image url in the database and then put that url in img tag src attribute. then it should show the image

CodePudding user response:

You can convert images to base64 format then save them on your database. Refer to the code below:

const fs = require('fs');
const contents = fs.readFileSync('/path/to/file.jpg', {encoding: 'base64'});
  • Related