i'm trying to upload image in Vue.js and send it to server with axios but there is some error i'm getting.
First of all:
I'm trying to send it like a formData. Not a base64 format.
here is my input:
<label>File
<input type="file" id="file" ref="file" v-on:change="onChangeFileUpload()"/>
</label>
<button v-on:click="submitForm()">Upload</button>
and here is my data layer and methods:
export default {
data() {
return {
file: ''
}
},
methods: {
submitForm(){
let formData = new FormData();
formData.append('file', this.file);
this.axios.post('apiURL',
formData,
{
headers: {
'Content-Type': 'multipart/form-data',
'token': '030303039jddjdj'
}
}
).then(function(data){
console.log(data.data);
})
.catch(function(){
console.log('FAILURE!!');
});
},
onChangeFileUpload(){
this.file = this.$refs.file.files[0];
}
}
}
and i'm trying to show image before sending to server.
<img :src="file" />
but i can't display image
i'm getting error:
[object%20File]:1 GET http://localhost:3000/[object%20File] 404 (Not Found)
where i'm mistaken?