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 :: how to find the last word of a string in javascript 
Javascript :: how to check if all inputs are not empty with javascript 
Javascript :: jquery child selector 
Javascript :: replace many chracters js 
Javascript :: for loop in vue 
Javascript :: jquery element width 
Javascript :: referenceerror document is not defined node js 
Javascript :: node require module 
Javascript :: toastify 
Javascript :: promisify 
Javascript :: react prevent component from update once mounted 
Javascript :: javascript anagram 
Javascript :: javascript stop execution 
Javascript :: simple javascript function 
Javascript :: import bootstrap in react 
Javascript :: js scroll to id on body 
Javascript :: get font size jquery 
Javascript :: chrome.storage.local get 
Javascript :: join method javascript 
Javascript :: javascript copy 2d array 
Javascript :: biding multiple class vuejs 
Javascript :: avascript regex email 
Javascript :: javascript object to array 
Javascript :: redux extension 
Javascript :: javascript onkeydown 
Javascript :: get element of an array inside another array 
Javascript :: npm install nodemon 
Javascript :: javascript loop object 
Javascript :: website design html css javascript 
Javascript :: get server by id discord.js 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =