jeudi 22 juillet 2021

Error processing image with dropzone in laravel 5.6

I´m trying to upload a file with dropzone and laravel 5.6, but my method returns a 405 (Method Not Allowed) error and I don´t know how I can add a token to process the upload.

This is my code in my blade:

<form action="" enctype="multipart/form-data" class="dropzone" id="fileupload" method="POST">
                                    <div class="col-12 mt-3 text-center">
                                        <span>Arrastre o pulse aquí para subir archivos</span>
                                    </div>
                                    <div class="col-12 text-center mt-4 mb-4">
                                        <i class="fas fa-upload fa-4x"></i>
                                    </div>
                                    <div class="col-12 mt-5 text-center">
                                        <span>El tamaño máximo del archivo debe ser inferior a 6MB</span>
                                    </div>

                                    <div class="fallback">
                                        <input name="file" type="files" multiple accept="image/jpeg, image/png, image/jpg" />
                                    </div>
                                </form>

and this is my js script:

<script>
        var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
        Dropzone.options.myDropzone = 
        {
            url: "",
            headers: {
                'x-csrf-token': CSRF_TOKEN,
            },
            method: "POST",
            data: {"_token": $("meta[name='csrf-token']").attr("content")},
            autoProcessQueue: true,
            maxFilesize: 6,
            acceptedFiles: ".jpeg, .jpg, .png, .gif",
            addRemoveLinks: true,
            paramName: "attached",
            init: function() {
                dzClosure = this;
                this.on("sending", function(data, xhr, formData) {
                    var token = $("meta[name='csrf-token']").attr("content");
                });

                // for Dropzone to process the queue (instead of default form behavior):
                /*document.getElementById("submit-all").addEventListener("click", function(e) {
                    // Make sure that the form isn't actually being sent.
                    e.preventDefault();
                    e.stopPropagation();
                    dzClosure.processQueue();
                });



                //send all the form data along with the files:
                this.on("sendingmultiple", function(data, xhr, formData) {
                    formData.append("firstname", jQuery("#firstname").val());
                    formData.append("lastname", jQuery("#lastname").val());
                });*/
            },
            success: function(file, response) 
            {
                console.log(response);
            },
            error: function(file, response)
            {
               return false;
            }
        }
    </script>

Thanks for reading, any help would be much appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire