Uploading files with Vue-Resource

2

How do I upload an image with Vue-Resource!?

I have tried in many ways but I can not! Does anyone have a working example?

    
asked by anonymous 13.07.2016 / 21:29

1 answer

5

I got it !!

Someone needs to know:

methods: {
  send() {
      let data = new FormData();

      data.append('file', this.record.file)
      this.$http.post('test', data);
    },
    upload(e) {
      e.preventDefault();
      var files = e.target.files;
      this.record.file = files[0];
    }
}
<div class="col-sm-12">
  <input @change="upload" type="file">
</div>
<div class="col-sm-12">
  <button @click="send">Send</button>
</div>

On the server just give dd($request->all()) that the file will be there!

    
13.07.2016 / 21:48