React.js, how to send a multipart/form-data to server

前端 未结 6 1014
走了就别回头了
走了就别回头了 2020-12-14 01:35

We want to send an image file as multipart/form to the backend, we try to use html form to get file and send the file as formData, here are the codes

export          


        
6条回答
  •  不思量自难忘°
    2020-12-14 02:37

    We just try to remove our headers and it works!

    fetch("http://localhost:8910/taskCreationController/createStoryTask", {
          mode: 'no-cors',
          method: "POST",
          body: data
        }).then(function (res) {
          if (res.ok) {
            alert("Perfect! ");
          } else if (res.status == 401) {
            alert("Oops! ");
          }
        }, function (e) {
          alert("Error submitting form!");
        });
    

提交回复
热议问题