title: TypeError: Cannot create property 'data' on string
body: <p>I have a Node.js blog API. Currently I post a JSON object containing a title and content using Insomnia. I'd now like to include an image in my post.</p>
  <p>My Json looks like this:</p>
  <pre><code>    {
          &quot;post&quot;: {
              &quot;title&quot;: &quot;My title&quot;,
              &quot;content&quot;: &quot;This content&quot;,
              &quot;image&quot;: &quot;/path/to/image.jpg&quot;
          }
      }
  </code></pre>
  <p>My <code>addPost</code> function contains:</p>
  <pre class="lang-js prettyprint-override"><code>    newPost.image.data = fs.readFileSync(newPost.image);
      newPost.image.contentType = 'image/jpeg';
  
      // Let's sanitize inputs
      newPost.title = sanitizeHtml(newPost.title);
      newPost.content = sanitizeHtml(newPost.content);
  </code></pre>
  <p>I get this error:</p>
  <blockquote>
  <p>TypeError: Cannot create property 'data' on string '/path/to/image.jpg'</p>
  </blockquote>
  <p>I think this because <code>newPost.image.data</code> expects an object but <code>fs.readFileSync(newPost.image)</code> is a string. I don't know how to deal with this though. Can anybody offer any suggestions?</p>
  <p><strong>Full addPost function:</strong></p>
  <p><strong>Full addPost code:</strong></p>
  <pre><code>PostController.addPost = async (req, res) =&gt; {
  
      try {
          if (!req.body.post.title || !req.body.post.content) {
              res.status(403).end();
          }
  
          const newPost = new Post(req.body.post);
  
          newPost.image = {};
          newPost.image.data = fs.readFileSync(newPost.image);
          newPost.image.type = 'image/jpeg';
  
          // Let's sanitize inputs
          newPost.title = sanitizeHtml(newPost.title);
          newPost.content = sanitizeHtml(newPost.content);
  
          newPost.slug = slug(newPost.title.toLowerCase(), { lowercase: true });
          newPost.cuid = cuid();
  
          newPost.save((err, saved) =&gt; {
              if (err) {
                  res.status(500).send(err);
              }
              res.json({ post: saved });
          });
      }
      catch (err) {
          console.log(err);
      }
  }
  </code></pre>
  <p><strong>Post</strong></p>
  <pre class="lang-js prettyprint-override"><code>    import mongoose from 'mongoose';
      const Schema = mongoose.Schema;
  
      const postSchema = new Schema({
          title: { type: 'String', required: true },
          content: { type: 'String', required: true },
          image: { data: Buffer, type: 'String', required: true }, //added when trying to get the image to post
          slug: { type: 'String', required: true },
          cuid: { type: 'String', required: true },
          dateAdded: { type: 'Date', default: Date.now, required: true },
  });
  
      let Post = mongoose.model('Post', postSchema);
  
      export default Post;
  </code></pre>