title: How to fix image upload in Axios
body: <p>I'm having trouble in uploading image in react. I use axios for the api request and multer &amp; cloudinary for the file upload.</p>
  
  <p><strong>Update:</strong> 
  In my dependency:
  "axios": "^0.19.0"</p>
  
  <p>Required dependencies in my .js file:
  import axios from 'axios';</p>
  
  <p><strong>The image upload already worked in my backend</strong> using express. But in react it still doesn't work. I've already checked everything and it seems fine.
  Below is the code:</p>
  
  <pre><code>  const [text, setText] = useState('');
    const [image, setImage] = useState([]);
  
    const onSubmit = async e =&gt; { 
      e.preventDefault();
      let data = new FormData();
      console.log(image + ' ' + 'this is image pathname')
      data.append('image', image);
  
        axios.post('/api/posts/image', data)
       .then(res =&gt; {
          console.log(res.data + 'this is data after api call');
       })
       .catch(err =&gt; console.log(err));
    };
  
  return (
     &lt;Fragment&gt;
        &lt;form onSubmit={e =&gt; onSubmit(e)} className="create-post-form"&gt;
           &lt;input
        type="file"
        placeholder="Write something..." 
        name="image"
        value={image}
            onChange={e =&gt; setImage(e.target.value)}
           /&gt;
          &lt;br/&gt;
      &lt;button className="btn btn-post"&gt;Post&lt;/button&gt;
        &lt;/form&gt;
    &lt;/Fragment&gt;
  );
  </code></pre>
  
  <p><strong>UPDATE Server side code:</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>app.post('/image', upload.single('image'), async (req, res) =&gt; {
  
      try {
          const result = await cloudinary.v2.uploader.upload(req.file.path);
          res.send(result);
      } catch(err) {
          res.status(500).send('Server Error');
      }
  });
  </code></pre>
  
  <p>Error message: POST <a href="http://localhost:3000/api/posts/image" rel="nofollow noreferrer">http://localhost:3000/api/posts/image</a> 500 (Internal Server Error)</p>