score:1

here is the documentation about the file upload it can help you https://strapi.io/documentation/3.x.x/guides/upload.html#file-upload.

so first you have to create your book entry without your image.

and then you have to upload your files and set the entry you want to link.

so it will be 2 request for that.

here is an example https://strapi.io/documentation/3.x.x/guides/upload.html#examples we link an image to an existing article.

score:1

took a while to work out but here's how i did it:

const submitupload = e => {
  e.preventdefault();

  const formdata = new formdata(e.target);

  axios.post("http://localhost:1337/images", {})
    .then(res => {
      console.log(res);

      formdata.append('refid', res.data.id);

      axios.post(`http://localhost:1337/upload`, formdata, {
        headers: { 'content-type': 'multipart/form-data' },
      })
        .then(res => {
          console.log(res);
        })
        .catch(err => {
          console.log(err);
        });
    })
    .catch(err => {
      console.log(err);
    });
}

return (
  <form id='form' onsubmit={e => submitupload(e)}>
    <input type="file" name="files" />
    <input type="text" name="ref" value="image" />
    <input type="text" name="field" value="image" />
    <input type="submit" value="submit" />
  </form>
)

the ref and refid input values' meanings are given here https://strapi.io/documentation/3.x.x/guides/upload.html#examples.


Related Query

More Query from same tag