DjKillerMemeStar
DjKillerMemeStar

Reputation: 425

Dropzone send empty

I have a dropzone setup with the following script:

    <script>
    Dropzone.options.myDropzone = {
        url: 'assets/PHP/createNieuws.php',
        autoProcessQueue: false,
        uploadMultiple: true,
        parallelUploads: 1,
        maxFiles: 1,
        maxFilesize: 1,
        acceptedFiles: 'image/*',
        addRemoveLinks: true,
        createImageThumbnails: true,
        init: function () {
            dzClosure = this; // Makes sure that 'this' is understood inside the functions below.

            this.on("success", function (file, responseText) {
                console.log(responseText);
            });

            // for Dropzone to process the queue (instead of default form behavior):
            document.getElementById("submit").addEventListener("click", function (e) {
                // Make sure that the form isn't actually being sent.
                e.preventDefault();
                e.stopPropagation();
                if (dzClosure.getQueuedFiles().length > 0) {
                    dzClosure.processQueue();
                } else {
                    dzClosure.uploadFiles([{ name: 'nofiles' }]); //send empty
                }
            });

            //send all the form data along with the files:
            this.on("sendingmultiple", function (data, xhr, formData) {
                formData.append("titel", jQuery("#titel").val());
                formData.append("artikel", jQuery("#artikel").val());
            });
        }
    }
</script>

And i also have a file named default.png on my server. I would like dropzone to refer to default.png if no image is detected. As you can see i've tryed this solution already to no succes: https://stackoverflow.com/a/41044001/6396380

This returns the following error in my chrome console:

dropzone.js:1497 Uncaught TypeError: Cannot read property 'filename' of undefined

My dropzone version is 5.1.0 .

Any idea's on how to fix this?

Upvotes: 2

Views: 3559

Answers (2)

Bogdan Ostashevsky
Bogdan Ostashevsky

Reputation: 41

For people having errors on firefox due to append method while using uploadFiles function but still wants to get that phat xhr request submitted with everything handled for you I suggest instead of using

dropzone.uploadFile({
    name: 'nofiles',
    upload: {
        filename: 'nofiles'
    }
})

to use

dropzone._uploadData(
    [
        {
            upload: {
                filename: '' 
            }
        }
    ],
    [
        {
            filename: '',
            name: '',
            data: new Blob()
        }
    ]
);

Upvotes: 3

enyo
enyo

Reputation: 16706

This happens because the new version assumes that there is a file.upload object with filename. Changing your mock file to

{ name: 'nofiles', upload: { filename: 'nofiles' } }

should do the trick.

You should also upgrade to 5.1.1 because it solves a bug related to this.

Upvotes: 2

Related Questions