I can't upload image to strapi

I am trying to upload image to strapi, but i am getting error 400 ,this my code :
I guess the error because it can’t read the file input i am not sure 🤔

 <script>

    import axios from "axios";
    // const files = document.getElementById('file');
    let formData = new FormData();
    var file = document.querySelector('form');
    
      let handleUpload = () => {
    
   // You should have a server side REST API 
   axios.post('http://localhost:1337/upload',
       formData,{   
            headers: {
              'Content-Type': 'multipart/form-data'
            }
          }
        ).then(function () {
          console.log('SUCCESS!!');
        })
        .catch(function () {
          console.log('FAILURE!!');
        });
    };

</script> 

<div class="card" >
    <form id="myFrom" >
      <input
        type="file"
        id="image"
        name="file"
        alt="image"
      />
      <br />
      <button type="submit"on:click={handleUpload()}>Send</button>
    </form>
  </div> 
     

this there showing in my browser

72 thoughts on “I can't upload image to strapi”

  1. Hi I am so excited I found your webpage, I really found you by mistake, while I was researching on Bing for something else,
    Anyways I am here now and would just like to say
    many thanks for a incredible post and a all round interesting blog (I also love the
    theme/design), I don’t have time to go through it
    all at the moment but I have saved it and also added your RSS feeds, so when I have time I
    will be back to read much more, Please do keep up the superb job. https://buszcentrum.com/clomid.htm

    Reply

Leave a Comment