title: getting error while trying to upload image to node server
body: <p>Using this tutorial I want to upload images to my database, So I have this in server side:</p>
  <pre><code>router.post('/upload', upload.single('upload'), async (req, res) =&gt; {
      try {
          const incident = await Incident.findById(req.body.id)
          incident.image = req.file.buffer
          incident.save()
          res.send()
      } catch (e) {
          res.status(400).send(e)
      }
  }, (error, req, res, next) =&gt; {
      res.status(400).send({
          error: error.message
      })
  })
  </code></pre>
  <p>And I have the binary data of the image like this in front end:</p>
  <blockquote>
  <p>data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAIQAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAA</p>
  </blockquote>
  <p>In the tutorial it shows us that we can send a image via postman like this:</p>
  <p><a href="https://i.stack.imgur.com/ZkzvU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZkzvU.png" alt="enter image description here" /></a></p>
  <p>I used this to do the same thing as tutorial did in postman using fetch api with no luck:</p>
  <pre><code>const data = new FormData();
  data.append(&quot;upload&quot;, image); // the image is the binary data I showed you
  
  fetch('/accounts/upload', {
          // headers: {
          //     'Accept': 'application/json',
          //     'Content-Type': 'application/json'
          // },
          method: 'post',
          body: data,
      })
      .then(response =&gt; response.json())
      .then(result =&gt; console.log(result))
      .catch(error =&gt; console.log(error));
  
    
  </code></pre>
  <p>But I get <code>400 (Bad Request)</code> each time!!</p>
  <p>How can I fix this?</p>
  <p>I figured out that <code>req.body</code> is empty object like : {} So I think there is something wrong with fetch maybe</p>
  <p>EDIT 2: Here is a log from data inside:</p>
  <pre><code>function uploadImage(image) {
        const data = new FormData();
        data.append(&quot;upload&quot;, image);
        console.log(data); // added this to log the data
        fetch('/accounts/upload-image', {
            method: 'post',
            body: data,
        })
        .then(response =&gt; response.json())
        .then(result =&gt; console.log(result))
        .catch(error =&gt; console.log(error));
      }
  </code></pre>
  <p>Result o the log is:</p>
  <p><a href="https://i.stack.imgur.com/3eU3T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3eU3T.png" alt="enter image description here" /></a></p>