How to trigger Uploadify onError event handler?

Rosdi Kasim picture Rosdi Kasim · Jan 10, 2010 · Viewed 10.4k times · Source

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 event 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?

Answer

Sampson picture Sampson · Jan 10, 2010

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