Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

axios send file

var formData = new FormData();
var imagefile = document.querySelector('#file');
formData.append("image", imagefile.files[0]);
axios.post('upload_file', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
})
Comment

axios get data from json file

axios.get('data.json')
    .then(res => console.log(res.data))
    .catch(err => console.log(err)
Comment

axios send file with data

const photoFormData = new FormData();
    // dict of all elements
    photoFormData.append("avatar", file);
    photoFormData.append("email", this.state.email);
    photoFormData.append("name", this.state.name);
Comment

sending api request in axios with files

 let headers = {
        Authorization: "token",
        'Content-Type':'multipart/form-data'
    };

let formData = new FormData();

 for(let key in files){
 
  formData.append('files[][file]', files[key].file, files[key].file.name)
  formData.append('files[][file_type_id]', files[key].fileType)
}

axios
    .post(
        "/api/files",
       formData,
        { headers }
    )
    .then(()=>{console.log('It Works')})
Comment

PREVIOUS NEXT
Code Example
Javascript :: if else react render in jsc 
Javascript :: react useeffect hook 
Javascript :: underline unused code vscode 
Javascript :: duplicate images in webpage js 
Javascript :: react hook form with controlled input 
Javascript :: get all data in collection firebase react 
Javascript :: nuxt history back 
Javascript :: outputstream to image js example 
Javascript :: alert message 
Javascript :: write a javascript code to display multiplication table in table 
Javascript :: axios.get Uncaught (in promise) TypeError: response.json is not a function 
Javascript :: add image inside a div on specific position javascript 
Javascript :: disable eslint curly option 
Javascript :: convert days to weeks and days javascript typescript 
Javascript :: how to set image width and height dynamically in javascript 
Javascript :: js set css 
Javascript :: register service worker 
Javascript :: package.json merger 
Javascript :: paypal in react js 
Javascript :: react-phone-number-input properties 
Javascript :: regex for fullstop 
Javascript :: javascript modify href attr 
Javascript :: js how to to attach an event handler only once 
Javascript :: textarea events react testing library 
Javascript :: enable emmet in vscode for jsx 
Javascript :: react form hook trigger is not a function 
Javascript :: mongoose discriminator 
Javascript :: javascript Display Time Every 3 Second 
Javascript :: add css class to button javascript 
Javascript :: callback in js 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =