Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

axios file upload

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

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

upload file axios

uploadFile: function (event) {
    const file = event.target.files[0]
    axios.post('upload_file', file, {
        headers: {
          'Content-Type': file.type
        }
    })
}
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 :: split 2 arrays javascript 
Javascript :: for in react 
Javascript :: how to clear state in react hooks 
Javascript :: react import json 
Javascript :: js substring first 4 numbwe 
Javascript :: useeffect async await 
Javascript :: js set iframe src 
Javascript :: Add an element to an array at a specific index with JavaScript 
Javascript :: ERROR Invariant Violation: requireNativeComponent: "RNCViewPager" was not found in the UIManager. 
Javascript :: chart js radar grid color 
Javascript :: jquery declare variable 
Javascript :: javascript anagram two strings 
Javascript :: document.append 
Javascript :: or operator in javascript 
Javascript :: string to currency javascript 
Javascript :: how can ic get the id of div jq 
Javascript :: adjacent elements product javascript 
Javascript :: yagni 
Javascript :: javascript join array 
Javascript :: How To Open Phone Dialer and Make Call From React Native App 
Javascript :: javascript convert image to base64 
Javascript :: how to break the foreach loop in javascript 
Javascript :: javascript convert array to object 
Javascript :: toarray javascript 
Javascript :: checkbox jquery checked 
Javascript :: get timezone name from date javascript 
Javascript :: javascript code to open excel file and read contents 
Javascript :: jquery detect textarea change 
Javascript :: javascript queryselector 
Javascript :: hover material ui styles 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =