vendredi 27 mars 2020

Upload PDF file with laravel and vuejs

i try to upload a pdf file and insert it to DB in my project using laravel+vuejs but 405 error shown 405 (Method Not Allowed) any help guys ?? this is ProjectDetail.vue:

       <form @submit="formSubmit" enctype="multipart/form-data">
         <input type="file" name="file" v-on:change="onFileChange">
         <button class="btn btn-success">Submit</button>
       </form>
              onFileChange(e){
            console.log(e.target.files[0]);
            this.file = e.target.files[0];
        },
        formSubmit(e) {
            e.preventDefault();
            let currentObj = this;

            const config = {
                headers: { 'content-type': 'multipart/form-data' }
            }

            let formData = new FormData();
            formData.append('file', this.file);

            axios.post('api/formSubmit/'+this.key, formData, config)
            .then(function (response) {
                currentObj.success = response.data.success;
            })
            .catch(function (error) {
                currentObj.output = error;
            });
        },

and this is route :

Route::post('/formSubmit/{id}','API\FileController@formSubmit');

and this id my controller:

 public function formSubmit(Request $request,$id)
{
    $fileName = time().'.'.$request->file->getClientOriginalExtension();
    $request->file->move(public_path('upload'), $fileName);
    $project =Projet::where('id',$id)->first();
    $project->file= $request->file;
    return response()->json(['success'=>'You have successfully upload file.']);
}

}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3bBCaE9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire