Skip to content

Instantly share code, notes, and snippets.

@cn-2k
Created November 18, 2021 11:32
Show Gist options
  • Save cn-2k/0de8524ad242cfa0540406403ae7e38c to your computer and use it in GitHub Desktop.
Save cn-2k/0de8524ad242cfa0540406403ae7e38c to your computer and use it in GitHub Desktop.
Upload image with form data + Vue and Axios
// It's just a piece of code.
const token = VueCookieNext.getCookie('token')
let formData = new FormData()
const state = reactive({
photo: null,
})
formData.append('name', fullName.value)
formData.append('email', email.value)
formData.append('photo', state.photo)
axios
.post('YOUR API URL', formData, {
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment