Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
  });
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Axios #FormData #JSON
ADD COMMENT
Topic
Name
4+4 =