title: Image data not saving to MongoDB
body: <p><em>Preface: using Node.js w/Express to build a blog website and using multer to upload an image to mongoDB.</em></p>
  <p>I have a problem with image data not saving to MongoDB.</p>
  <p>When I use enctype=&quot;multipart/form-data in my HTML form, I get the following in my terminal</p>
  <pre><code>fieldname: 'myImage',
    originalname: 'photo_2021-12-27_20-07-58.jpg',
    encoding: '7bit',
    mimetype: 'image/jpeg',
    destination: './uploads/',
    filename: 'photo_2021-12-27_20-07-58.jpg',
    path: 'uploads\\photo_2021-12-27_20-07-58.jpg',
    size: 134172
  }
  </code></pre>
  <p>Which is correct, the image also uploads into a separate uploads folder which is also correct, however the image data doesn't save to my mongoDB.</p>
  <p>However, when I remove enctype=&quot;multipart/form-data&quot;, I don't have the file data in my terminal, nor does the image upload to the separate folder. However I DO! get the image data in my mongoDB. This is such a weird problem. Can anyone help?</p>
  <p>Also, sorry for the amount of code I have just unleashed. If anyone actually takes the time to answer this then thank you!</p>
  <p><strong>Routes</strong></p>
  <pre><code>const express = require('express');
  const router = express.Router();
  const blogController = require('../controllers/blogController')
  const multer = require('multer');
  
  
  const storage = multer.diskStorage({
    //destination for files
    destination: function (request, file, callback) {
      callback(null, './uploads/');
    },
  
    //add back the extension
    filename: function (request, file, callback) {
      callback(null, file.originalname);
    },
  });
  
  
  const upload = multer({
    storage: storage,
  });
  
  router.get('/create', blogController.blog_create_get);
  
  router.get('/', blogController.blog_home);
  
  router.post('/', upload.single('myImage') ,blogController.blog_create_post);
  
  router.get('/:id', blogController.blog_details);
  
  router.delete('/:id', blogController.blog_delete_post);
  
  module.exports = router
  
  
  </code></pre>
  <p><strong>Controller code</strong></p>
  <pre><code>const blog_create_post = (req, res) =&gt; {
    console.log(req.file);
    const blog = new Blog(req.body, {
  
    })
  
    blog.save()
      .then(() =&gt; {
        res.redirect('/blogs')
      })
      .catch((err) =&gt; {
        console.log(err);
      })
  }
  </code></pre>
  <p><strong>Schema</strong></p>
  <pre><code>
    image: {
  
      data: Buffer,
      contentType: String
     
    },
  
  
  const Blog = mongoose.model('Blog', blogSchema)
  module.exports = Blog;
  
  </code></pre>
  <p><strong>Midleware</strong></p>
  <pre><code>// Static Files | Middleware
  app.use(express.static('Public'));
  app.use(express.urlencoded({ extended: true }));
  app.use(morgan('dev'))
  app.use('/uploads',express.static('uploads'))
  
  </code></pre>
  <p><strong>HTML form</strong></p>
  <pre><code>    &lt;form action=&quot;/blogs&quot; enctype=&quot;multipart/form-data&quot; method=&quot;POST&quot;&gt;
        &lt;label for=&quot;image&quot;&gt;Select image:&lt;/label&gt;
        &lt;input type=&quot;file&quot; id=&quot;image&quot; name=&quot;myImage&quot; accept=&quot;image/*&quot;&gt;
        &lt;input type=&quot;submit&quot; value = &quot;Upload Photo&quot;&gt;
  
  </code></pre>