Answer the question
In order to leave comments, you need to log in
How to upload an image to a local server via axios?
Good day. I work with VUEJS. It is possible to load the image into a variable.
<md-file type="file" @change="onFileSelected" v-model="NewPost.cover" accept="image/*" />
<md-button class="md-raised md-primary" @click="onUpload">Загрузить</md-button>
methods: {
onFileSelected: function(event){
this.selectedimage = event.target.files[0]
},
onUpload: function(){
const fd = new FormData();
fd.append('image', this.selectedimage, this.selectedimage.name);
axios.post("/img", fd)
.then(function(response){
console.log(response);
});
},
}
Answer the question
In order to leave comments, you need to log in
js in the browser does not have access to the file system, you will not be able to save the image this way. For this you need either php or node.js
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question