laravel dropzone组合形式错误405(方法不允许)

时间:2017-06-13 10:10:19

标签: jquery laravel-5 laravel-5.3 dropzone.js

美好的一天,我已经成功地将dropzone与普通形式结合起来并且它可以正常工作但我尝试使用方法PUT或PATCH更新帖子(用户内容),我得到错误405(方法不允许)。 发布更新工作没有dropzone但是当图像被添加到dropzone时我得到错误405(方法不允许)

            <form id="addproduct" enctype="multipart/form-data" method="POST" action="{{ route('admin.posts.update', $post->id) }}">
                {{ csrf_field() }}
                {{method_field('PATCH')}}

                <input class="form-control" name="title">
                <div id="myAwesomeDropzone" class="dropzone"></div>
                <button type="button" id="submit_form" class="btn btn-primary">Send</button>
            </form>


            <script>

            Dropzone.options.myAwesomeDropzone = {
                url: '/admin/posts/{!! json_encode($post->id) !!}',
                method: 'PUT',
                autoProcessQueue: false,
                uploadMultiple: true,
                parallelUploads: 3,
                maxFiles: 3,
                addRemoveLinks: true,
                thumbnailMethod: 'crop',
                resizeWidth: 500,
                resizeHeight: 500,
                resizeQuality: 0.3,
                acceptedFiles: ".jpg, .jpeg, .png",
                dictDefaultMessage: "Drop your files here!",


                init: function () {
                    var myDropzone = this;
                    $('#submit_form').on("click", function (e) {
                        e.preventDefault();
                        e.stopPropagation();
                        myDropzone.processQueue();      
                    });



                    this.on("sending", function(file, xhr, formData){
                        $('#addproduct').each(function() {
                            title = $(this).find('input[name="title"]').val();
                            formData.append('title', title);
                        });
                    });
                    this.on("success", function(file, response) {

                    });
                    this.on("completemultiple", function(files) {
                        // Here goes what you want to do when the upload is done
                        // Redirect, reload , load content ......

                    });
                },

            };

            </script>

1 个答案:

答案 0 :(得分:2)

尝试将方法更改为POST并将_method和_token输入附加到发送的formData。每次我使用不是GET,HEAD或POST的HTTP动词时,我都会将这些字段和POST包含在URL中。