title: Is there a way to let users directly upload image on cloudinary and store the url of the image in my mongoDB database in Node.js App
body: <p>I am currently storing images using multer to uploads folder in public and then to mongodb using buffer and converting back to 64bit to display it which I think its making website slow. 
  I know I'm new to all this , really need a step by step procedure and explanation. Thank you</p>
  
  <p>App.js-></p>
  
  <pre><code>const blogSchema=new mongoose.Schema({
  name:String,
  title:String,
  image:String,
  body:String,
  uploadImg:{ 
      data: Buffer, 
      contentType: String 
  },
  created:{
      //here we define a default date in case the user doesnt type one
      type:Date,default:Date.now
  }})
  </code></pre>
  
  <p>multer and storage-></p>
  
  <pre><code>function checkFileType(file,cb){   
  //allowed extensions
  //console.log(file);
  const filetypes=/jpeg|jpg|png|gif/;
  const extname=filetypes.test(path.extname(file.originalname).toLowerCase());
  const mimetype=filetypes.test(file.mimetype);
  if(mimetype &amp;&amp; extname){
      return cb(null,true)
  }else{
      //console.log(file);
      cb('Error : Only Images Accepted');
  }
  </code></pre>
  
  <p>} </p>
  
  <pre><code>var Storage = multer.diskStorage({
      destination:"./public/uploads/",
      filename:(req, file, callback)=&gt;{
          callback(null, file.fieldname+"-"+Date.now()+path.extname(file.originalname))
      },
  
  
  })
  
  var upload = multer({storage:Storage,
      limits:{fileSize:10000000},
      fileFilter:function(req,file,cb){
          checkFileType(file,cb)},      
          }
  ).single('file');
  </code></pre>
  
  <p>in post route-></p>
  
  <pre><code> var obj = { 
                     name:req.body.name,
                      title:req.body.title,
                       image:req.body.image,
                          body:req.body.body,       
                           uploadImg: { 
                          data: fs.readFileSync(path.join( './public/uploads/' + req.file.filename)), 
                          contentType: 'image/png'} }
  
                          Blog.create((obj),
  </code></pre>
  
  <p>in show.ejs-></p>
  
  <pre><code>&lt;img src="data:blog/&lt;%=blog.uploadImg.contentType%&gt;;base64,&lt;%=blog.uploadImg.data.toString('base64')%&gt;" alt="someImage"&gt;
  </code></pre>