Skip to content

Instantly share code, notes, and snippets.

@Adarshreddyash
Created December 27, 2020 05:07
Show Gist options
  • Save Adarshreddyash/7542611c53c990d5713e4bbe5d7fae89 to your computer and use it in GitHub Desktop.
Save Adarshreddyash/7542611c53c990d5713e4bbe5d7fae89 to your computer and use it in GitHub Desktop.
methods: {
uploadImage(event) {
let img = new FormData();
img.append("avatar", event.target.files[0]);
const base = {
baseURL: this.$store.state.endpoints.baseUrl,
headers: {
// JWT token !!!
Authorization: `JWT ${this.$store.state.jwt}`,
"Content-Type": "multipart/form-data"
},
xhrFields: {
withCredentials: true
}
};
const axiosInstance = axios.create(base);
axiosInstance({
url: "http://127.0.0.1:8000/userDetails/",
data: img,
method: "patch"
})
.then(response => {
console.log(response);
this.snackbar = true
})
.catch(error => {
console.log(error);
console.debug(error);
console.dir(error);
});
},
onButtonClick() {
this.$refs.uploader.click();
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment