Search code examples
jqueryfile-uploaduploadify

jQuery Uploadify Advanced File Validation Question


After long time of searching the best upload technique I've decided to go with jQuery Uploadify.

I got no problem implementing it into existing code, excluding one thing. I created strict upload validation rules.

The main problem is that onAllComplete() function returns success message. In my validation file I tried to use echo 'errror' and die('error') as well. Without any luck. I've searched Google and SO. Without any luck.

Do you have any ideas/advices/snippets? Any help appreciated.

Update
To make my situation clear. I'm using onComplete() function to show eventual but I have no idea how to force onAllComplete() function to show correct data.

Update 2 I applied IgalSt (I'm sure I did something similar before) but still having the same issue. My onComplete function looks as following now:

onComplete: function (ev, queueID, fileObj, response) {
    var result = $.parseJSON(response).success;
    alert(result);
            if (result == false) {
        alert('invalid')
    } else {
        alert('everything is OK');
        var size = Math.round(c.size/1024);
    }
    return false;
},

If I alert(response) it alertsfalse` so it should be working. Any suggestions why it's not? onAllComplete() function still shows this file as uploaded successfully.

Regards, Tom


Solution

  • as long as the server returns 200 state header you the onAllComplete callback will fire. onError callback will fire only when you've got an error header back: 500 or 404 for example. Therefore, your server side code should return a response with a flag if there was a problem and you should use onAllComple to do some kind of IF for than.

    For example if you page return a JSON with error:

    [{"success":"false"}]
    

    you onAllComplete function will look something like that:

    'onComplete':   function(ev, queueID, fileObj, response) {
                var result = $.parseJSON(response).success;
                if (!result)
                  alert('invalid')
                            else
                               alert('everything is OK');
            }