Uploading files with VueJS, axios and Laravel

后端 未结 2 1901
余生分开走
余生分开走 2020-12-19 17:12

Hello I am building one project. Where user can send up to 5 images and up to 10 songs with the text. But when I send request to the server, where I handle with Laravel, I c

相关标签:
2条回答
  • 2020-12-19 17:50

    Oh yeah! you're missing this part. You need to define this.

    axios.defaults.headers.post['Content-Type'] = 'multipart/form-data';
    
    0 讨论(0)
  • 2020-12-19 18:01

    this my solutuion

    export default {
        data (){
            return {
                attachment : { name : null,file: null }
            }
        },
        methods : {
            onFileChange(event) {
                this.attachment.file = event.target.files[0]
            },
            attachmentCreate() {
                var form = new FormData();
    
                form.append('name',this.attachment.name);
                form.append('file',this.attachment.file);
                this.$http.post('attachment',form).then(response=>{
                   console.log("oke")
                })
            },
        }
     }
    <input type="file" class="form-control" @change="onFileChange">

    0 讨论(0)
提交回复
热议问题