Tuesday, July 03, 2007

SWFUpload Revision 6 Release

Update 7-5-2007

A couple issues were found in Revision 6. The major one was another race condition that could occur in IE6. Hopefully these race condition bugs have finally been squashed. A few other issues were found but were not noticeable since they kind of canceled each other out.

I've posted updated Demos and Source code. I'm not updating the version number so if you downloaded a copy before today I recommend that you download the updated copy.

SWFUpload Revision 6 Release

I am pleased to announce the release of Revision 6 of SWFUpload. This version has been moved forward to ActionScript 3.0 and Flash Player 9 which gives us some power features what everyone has been waiting for.

What's new:
  • Code moved to ActionScript 3.0.
  • Flash Player 9 required.
  • Added ability to send custom POST values.
  • Added a fileValidation event that allows each file to be validated before upload.
  • The fileComplete event receives the output from the server.
  • File type (extension) is checked again in code since the file browser can be bypassed.
  • The file post variable name (aka Filedata) can now be changed.
  • Fixed a bug caused by canceling single files.
  • Removed the cookie sending feature. The post_params setting can be used.
  • Removed query_params. Use post_params instead.
  • Fixed another race condition that could prevent SWFUpload from loading on a page refresh.
  • Updated PHP and ASP.Net demos.
How to use it

See the demos and download Revision 6 at our generously hosted site (thanks again!). I have had some trouble with browsers/proxies caching some of the old JavaScript files. If it doesn't work make sure your caches are cleared.

My next project is to produce documentation for SWFUpload. I don't plan any new features (unless Flash Player 10 fixes/adds cool features) except bug fixes.

Don't forget to show your support to the original SWFUpload developers. We're grateful for their innovation and hard work


  1. This is so awesome. I am VERY excited to put this into my project now.

    The events for after a file is uploaded will be great!

  2. Anonymous4:41 PM

    Great timing! I just spent too many hours mucking about to get around the lack of access to the response body in 5.2.
    Now, if only I could actually get some serverdata... I see there are some hooks there... and it seems to work in your demo, but I must be missing something...

    Anyway, thanks a million for your great work on this.

  3. You can get server data. The fileComplete event now sends the server data as a parameters.

    function fileCompleteHandler(fileObj, server_data) {

    The server data is exactly whatever text your upload backend script outputs. It does not include any HTTP overhead data (status code, cookies, etc).

  4. Anonymous3:49 AM

    can't work at ie6

  5. That's funny because I do my development in ie6 and I'm pretty sure it works.

    You need to have Flash Player 9 and JavaScript enabled.

    You could also be suffering from cached file issues. I always get my Handler.js files cached and it's the dickens to get them to update (I'm not sure if it's he browser or our proxy server).

  6. Good work! You made greate improvements! I'm using an Intel Mac with the latest FF. The new version throws an error:

    TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@14e3a291 to flash.net.FileReference.

    This error occurs after the file has been uploaded.

  7. Among the changes you mention is: "Fixed another race condition that could prevent SWFUpload from loading on a page refresh."

    I'm not ready to move to AS3 yet so I need to use SWFUpload 5.2. Does the race condition affect that version? If so, can you provide any details on the problem or the fix so I can try to patch 5.2?

    Thanks for all your work!

  8. SWF DEBUG: SWFUpload Init Complete
    SWF DEBUG: ControlID: SWFUpload_3
    SWF DEBUG: Upload Target URL: ../featuresdemo6/upload.php?id=bob
    SWF DEBUG: Begin Upload on Queue: false
    SWF DEBUG: Validate Files: true
    SWF DEBUG: File Types String: *.*
    SWF DEBUG: Parsed File Types:
    SWF DEBUG: File Types Description: All Files (*.*)
    SWF DEBUG: File Size Limit: 102400
    SWF DEBUG: File Upload Limit: 10
    SWF DEBUG: File Queue Limit: 0
    Flash called back and is ready.
    Could not find Flash element in setUploadSettings
    Could not find Flash element
    Could not find Flash element
    Could not find Flash element
    Could not find Flash element

  9. @robbin: Thanks for the info. It looks like I left some test code in and that I probably still have a race condition. Sheesh this is difficult. ;)

  10. @dean

    I believe I've finally fixed the race conditions. It ended up being a fairly easy change but requires the modification of code in several different places.

    Basically to update R52 you need to use lines 141 to 147 from R6 in loadFlash. It shouldn't be hard to merge that in to R52

    Then add lines 208 to 220 (the getMovieElement function) to R52.

    Then in all the Flash Control methods replace any reference to this.movieElement with this.getMovieElement(). You can see in R6 how I did it.

    To explain:
    Anywhere that the script refers to this.movieElement it is possible that this.movieElement has not been set yet because Flash may get executed before SWFUpload has completed initializing.

    To avoid this you first replace any reference to this.movieElement with the this.getMovieElement() function which just does a document.getElementById to go and grab the movie element. That way we are 100% sure we've got it even if the Flash runs early.

    This required some minor changes to loadFlash to make sure the element is actually added to the document before the flash is added.

    It shouldn't be difficult to see the changes from R5.2 to R6.

    Good luck.

  11. @Jasper

    The error your reported may be a Mac Flash Player issue. Unfortunately I don't have access to equipment for testing on Macs. If you can provide more detail about when and where the error occurred it is possible that I could track it down.

  12. Hi Jake,

    It's an interesting issue! I hope we are able we can fix it!
    What kind of information do you want? If you want me to test any updates as a mac user, please send me an email (jasper@royalfish.nl)! I'm very willing to help.
    I'm unable to post the debug log because of the html output. I was unable to find your email address to send it to you.

  13. @jake

    thanks for your great work! I was just going to report a IE6 bug, but opened your blog-post only to see you've already updated the code.

    Once again, thanks for the commitment!

    And, for anyone trying to implement this great package in conjunction with the CakePHP theframework - you might want to turn-off the time-elapsed report from the end of your view (e.g. <!-- 0.139s -->) if you're trying to return JSON formatted data from it - IE6 throws an exception with a 'Syntax error' message when you issue an eval() in your callbacks.

    If you don't want to zero your (CakePHP) debug level globally, you can do this on a per action basis - in your action implementing an empty layout that you need to return JSON, write:

    Configure::write('debug', 0);

    That should prevent the profiling report from appearing near the bottom of your view output.

  14. Excuse me,Am having a problem with creating a Classic Form Demo of this tool with ASP.NET . Can anyone point to a reference sample?

  15. @jake and jasper

    It is not a mac issue. I am running Firefox on Windows XP and am recieving the same error at the same time (just after file upload).

    TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@97dfd01 to flash.net.FileReference.

    This happens on all the demos on the demo page.

  16. What version of Flash Player do you have?

  17. This comment has been removed by the author.

  18. From: Adobe Flash Player Version Checker

    Player version: WIN 9,0,60,120
    Debug Player: Yes

    The player installed is the one that comes with CS3 or an update of it. I thought it might be because of the debug version but debugging is turned off by default and checking the mm.cfg file it has not been turned on.

  19. Rob van der Burgt1:22 PM

    Got the exact same error here, the tester is running Vista Buisiness, internet explorer 7 the flash version is 9.0.45.

    I have no idea where it comes from.

  20. @jasper
    Send your detailed bug report to otijim - yahoo - com (hopefully spammers won't parse that ;) )

    I'm looking in to this TypeError issue. I haven't seen the error in my testing (tested in IE6, FF2, Safari 3(on XP)) so that means manually tracking it down which might take some time.

    Thanks for the bug reports. Keep'em comin'!

  21. This is awesome work, dude. What I miss is the ability to send some parameter to the browse function individually, like the filetype (*.gif or something) and the file size, so I could push diffrent file types in the queue.

  22. Found the bug and fixed it! The SWFUpload class should extend UIComponent instead of Sprite(import import mx.core.UIComponent)

    I found the sollution here (dutch):

    A build including the sourcecode is found here:

  23. Rob van der Burgt4:14 AM

    hmz, the URL is to long, here's a tinyurl


  24. @rob
    Thanks for the debug work! Were you able to determine which line of code was throwing the error? I do not receive this error message and would like to understand what is causing it and why extending UIComponent instead of Sprite fixes it (and I can't read dutch).

  25. Rob van der Burgt11:39 AM


    Some of my tester had the problem, some of them didn't. It didn't matter wich flash version they had even with exact the same browser version and flash version.

    The users wich did have the problem always got the error, there wasn't any way to reproduce it or get rid of it on the user side.

    This is actualy the first time I did some programming in flash. A translation of the sollution found in the forum:

    "Within the Flex Framework all stage elements have to extend UIComponent or a subclass from the component."

    Hopefully this information helps. One last note, when i imported UIComponent the build file size increased with about 60kb!

    Thanks for continuing the SWFUpload development.



  26. I believe I've uncovered the Type Coercion error issue. Looks like I forgot to update the File Complete event handler to the ActionScript 3.0 way of handling events.

    This explains why File Complete was not being called (I thought it was because the Server Data event over-rode it). Now the File Complete and Server Data are both called and the Type Coercion error should be gone.

    Now I need some feedback. Due to the architecture of Revision 6 I cannot allow both the File Complete and Server Data events be fired. File Complete is always called (when the file completes) but Server Data only gets called if the upload script returns something (so it may not get called depending on you upload script).

    My inclination is toward using the Server Data event and requiring that the upload script return something even if you don't have any data you need to return.

    The other option is to add new setting that specifies if you wish to use FileComplete or ServerData depending on your need.

    Currently both events call the same JavaScript handler. Only one event can be called. This design probably doesn't need to change.

    @zolti: I've thought about it and I think I'll add methods for updating nearly all the settings dynamically. I start The Revisions to provide an "advanced" SWFUpload that gives us more control. Don't shoot yourself in the foot ;)

    Expect a new version in the near future. I'll probably change the version number since functionality will be changing.

  27. Dear Jake,

    Thank you for this fine application. I am using it for a while now, but i am experiencing some very strange behaviour.

    I'm using SWFUpload as a part of a ASP.NET Photo Gallery upload application. When i test the upload locally (Using Visual Studio 2005), everything is fine. The files are uploaded using SWFUpload, resized, stored on the filesystem and the filenames are stored in the SQL Server database.

    When i upload the application to my production server, the application does not work anymore. SWFUpload is still working, so i can select and upload my images to the server. But when i look in the folder on the server where the images should be, the folder is empty. Also, the filenames are not added to the database.

    It seems to me that the Upload.aspx script is not called, or there is some kind of timeout, or block on the server.

    Can you help me find this problem? Do you need me to post some code?

    Thank you for your help!


  28. I frequently find moving from dev to production problematic (in general).

    All I can recommend is check your folder permissions and make sure you have appropriate Try/Catches and have the script return the 500 status code so you can tell if there was an error.

    Turn debugging on and see what messages you get. Make sure you have the Error handler set up so you get error messages when something goes wrong with the upload.

  29. One feature i wish was in here is the ability to reset the queue once you have uploaded so if needed you can upload the files again with out selecting the files again.

  30. Anonymous3:34 AM

    This comment has been removed by a blog administrator.

  31. So, I need to ensure that my app's cookie is passed along with the flash movies post request.

    How can I do this? I need to set the "Cookie" header property.

  32. I can't seem to get the fileValidation to fire. here is what I have:
    file_validation_handler : fileValidation,

    function fileValidation(fileObj) {
    try {
    } catch (ex) { this.debugMessage(ex); }

    return true;

    when I que up a file the alert does not fire.

    Anyone have any ideas?

  33. thorn9:57 AM

    Removed the cookie sending feature. The post_params setting can be used.

    Why did you do that? Cookie are used, for example, to pass session id in ASP.NET. Alternative solution is including session id in URLs, this is ugly.

  34. Anonymous5:51 AM

    This comment has been removed by a blog administrator.