YUI Uploader Error: plugin exception: "TypeError: Error #1009"

The Error

I've been working on a YUI Uploader integration for the past several hours, the last couple of which were spent troubleshooting the JavaScript error: "uncaught exception: Error calling method on NPObject! [plugin exception: "TypeError: Error #1009"]". This error would be raised as soon as the upload was started, and didn't appear to be related to any of my JavaScript functions.

What Caused It

The cause for me was actually very very simple, and can be reproduced on Yahoo's multiple file upload example. If you set the number of simultaneous uploads higher than the number of files you have in the queue, the flash uploader will try to perform file uploads on object that don't exist.

How I Fixed It

I added a test to make sure the number of files being uploaded was not smaller then the number of simultaneous uploads. Using YUI example mentioned earlier, here is the change needed to their upload function:

function upload() {
    if (fileList != null) {
            
        // Count the number of total files
        numberOfFiles = 0;
        for (i in fileList){numberOfFiles++}; 

        // Set the default limit
        simUploadLimit = parseInt(document.getElementById("simulUploads").value)
        
        // Test if default is larger, if so use the number of files as the limit
        simUploadLimit = numberOfFiles < simUploadLimit ? numberOfFiles : simUploadLimit;
        
        uploader.setSimUploadLimit(simUploadLimit);
        uploader.uploadAll("http://www.yswfblog.com/upload/upload_simple.php","POST",null,"Filedata");
    }
}

18 Comments

  • Ron said:
    1 year ago

    Thanks a lot for saving me a couple of hours of trying to track this down.

  • Adam said:
    1 year ago

    Thanks for the information! There are a lot of incorrect solutions out there.

  • Shane said:
    9 months ago

    Thanks a million, that did the trick. You are a Java JEDI!!

  • Sep said:
    8 months ago

    Thank UUUUUUUUU

  • Caleb said:
    8 months ago

    Thanks!

    I used this code for a default simultaneous upload of 2:

    var simUp = Math.min(2, fileList.length);

  • Shahnawaz said:
    7 months ago

    Thank for provide such a to the point help to resolve my problem.

  • Ronio said:
    6 months, 4 weeks ago

    Thank you very very much. by the way, when I run my page in IE, the uploadCompleteData event can't be triggered, but uploadComplete is ok. And with firefox, it also work well. Do you know the reason, thank you.

  • Taber said:
    6 months, 1 week ago

    wow, nice job figuring that out! and caleb, nice code-shortening job there. :) thanks a bunch for sharing, dudes.

  • Taber said:
    6 months, 1 week ago

    actually, it looks like fileList.length is undefined, caleb!

  • Alex said:
    6 months ago

    Thank you guys very much, you saved a loooottt of debugging time.

  • Darrell said:
    4 months, 2 weeks ago

    You Sir are the man!

  • Reghyt said:
    3 months, 2 weeks ago

    Thank you! like everyone above said, you saved me a lot of head scratching! :)

  • Colin said:
    3 months, 1 week ago

    Like everyone else above, thanks for posting this. I love the Internet. :)

  • mikee doodle said:
    2 months ago

    Thanks for posting this. Saved a lot of time.

    SWF should do the check in the future.

  • ivanski said:
    2 months ago

    SUPER !!!

    BRAVO !!!

    No1 !!!

  • Darny said:
    1 month, 3 weeks ago

    Thanks. You saved me a lot of time.

  • 1cbastian said:
    1 month, 2 weeks ago

    Thank you. Good job!

  • Johan said:
    2 weeks, 1 day ago

    I'm glad you posted this. THX

Submit a Comment