views:

1865

answers:

4

I am using Uploadify to upload files. Problem is, I need to inform users of any error during processing of those files.

Uploadify has onError, onComplete, and onAllComplete even handler but I do not know how to trigger these events so that users are informed of what is going on.

Do I need to send JSON string? There is a clue here and here and here but I couldn't make it to work. Perhaps the posting in the forum is outdated.

Anyone got any example that works for Uploadify 2.1?

+2  A: 

onError goes within the options of uploadify:

$("#fileInput").uploadify({
  onError: function(e, q, f, o) {
    alert("ERROR: " + o.info);
  }
});

From the Documentation

A function that triggers when an error occurs during the upload process. The default event handler attaches an error message to the queue item returning the error and changes it’s queue item container to red.

Four arguments are sent to the function:

  • event: The event object.
  • queueID: The unique identifier of the file that returned an error.
  • fileObj: An object containing details about the file that was selected.
    • name – The name of the file
    • size – The size in bytes of the file
    • creationDate – The date the file was created
    • modificationDate – The last date the file was modified
    • type – The file extension beginning with a ‘.’
  • errorObj: An object containing details about the error returned.
    • type – Either ‘HTTP’, ‘IO’, or ‘Security’
    • info – An error message describing the type of error returned
Jonathan Sampson
Yeah but I need to know the string format the server needs to write so uploadify know there is a problem during processing of the uploaded file. Lets say I want to display "Error on line 3, invalid dealer code: 'DEALER001'" to the user, how do I do it?
Rosdi
@Rosdi, the only effor/file information you have access to through uploadify is listed in my post above.
Jonathan Sampson
@Jonathan, ah.. so onError is not meant to provide custom error message to users. I should use onComplete instead.. thanks for the clarification.
Rosdi
A: 

i want know too

stefan
@stefan, use onComplete instead of onError. What I do is I return "OK" string if the upload was successful and return various error messages if the upload failed.Then in onComplete I check the returned string, if the string is not "OK" I then display the string (the error message) to user.
Rosdi
+1  A: 

This was killing me but I found a way. In the uploadify.php file I created all my validation. The difference here is that I set HTTP 4xx codes for each type of error.

if (! in_array($fileParts['extension'], $typesArray)) {
    header("HTTP/1.1 405);
    exit();
}

This throws the "405" error back to uploadify.js.

In the file I set $("#fileInput").uploadify() I added the "onError" function.

        'onError' : function(event, ID, fileObj, errorObj) {
        var r = "<br />ERROR: ";
        switch(errorObj.info) {
        case 405:
            r += "Invalid file type.";
            break;
        case 406:
            r += "Some other error.";
            break;
        }

        setTimeout('$("#fileInput'+ ID + 'span.percentage").html("'+r+'");',111);
    }

This forces the uploadify default function to exist while kind of extending it.

Hope this help!

Brant
@Rosdi This solution will allow you to put the error message in the div that contains the information on the file that failed. The alert method deletes the div as though it completed and then throws an alert.
Brant
A: 

onError: function (a, b, c, d) { if (d.status == 404) alert('Could not find upload script. Use a path relative to: '+''); else if (d.type === "HTTP") alert('error '+d.type+": "+d.status); else if (d.type ==="File Size") alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB'); else alert('error '+d.type+": "+d.text); },

Qazi Umar