Answers for "Axios FormData / not JSON"

3

axios post formdata

axios({
    method: 'post',
    url: 'myurl',
    data: bodyFormData,
    headers: {'Content-Type': 'multipart/form-data' }
    })
    .then(function (response) {
        //handle success
        console.log(response);
    })
    .catch(function (response) {
        //handle error
        console.log(response);
    });
Posted by: Guest on September-20-2020
0

Axios FormData / not JSON

var bodyFormData = new FormData();
bodyFormData.append('userName', 'Fred');

If you are uploading images, you may want to use .append
bodyFormData.append('image', imageFile); 

axios({
  method: "post",
  url: "myurl",
  data: bodyFormData,
  headers: { "Content-Type": "multipart/form-data" },
})
  .then(function (response) {
    //handle success
    console.log(response);
  })
  .catch(function (response) {
    //handle error
    console.log(response);
  });
Posted by: Guest on October-25-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language