P
P
Pavel2019-04-22 20:40:10
Vue.js
Pavel, 2019-04-22 20:40:10

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);
        
      });
    },
}

Having difficulty uploading an image to the server (local) via axios POST. I just want images (for example image.png) to be loaded into a folder with images (for example img). I didn't find a perfect answer. I would like to hear your opinion.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pautov, 2019-04-22
@bootd

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 question

Ask a Question

731 491 924 answers to any question