Dropzonejs trigger error and cancel upload

Viewed 2770

i'm using Dropzonejs and what I would like to do is essentially simple. But I can't find any article about it.

So on sending the file we trigger an error on nasty .exe and .php files. The dropzonejs interface show an X and and error message. So that's correct. The problem is that it still gets thrown into the on success event, and gets uploaded.

uploader.on("sending", function (file, xhr, data) {

    var aDeny = [ // deny file some extensions by default
        'application/x-msdownload',
        'text/php'
    ];

    if($.inArray(file.type, aDeny) !== -1) {
        this.defaultOptions.error(file, 'File not allowed: ' + file.name);
        return false;
    }
});

Evil.exe still appears in this success event and gets uploaded. The response only has a string of the file path and file.status is success.

uploader.on('success', function (file, response) {

    getData({'dostuff'});

    return file.previewElement.classList.add("dz-success");
});

So in my 'sending' event, how can I prevent the file from appearing in the success event?

UPDATE:

Thanks! This is what I needed in the end:

var aDeny = [ // deny file some extensions by default
    'application/x-msdownload',
    'text/php'
];

Dropzone.options.uploadWidget = {
    // more config...
    accept: function (file, done) {
        if ($.inArray(file.type, aDeny) !== -1) {
            done("This file is not accepted!");
        }
        else {
            done();
        }
    }
}
1 Answers
Related