Friday, May 11, 2007

Revision 5.2 update

I have posted an update to SWFUpload Revision 5.2. It does not add new features so I decided to keep the version number. Several function names have changed, however, so you can't just drop in the new swfupload.swf and swfupload.js files.

Changes
  • Added the Application Demo which demonstrates a working upload script and dealing with passing PHP Session IDs to the upload script as a work-around to the Flash/Firefox cookie issue.
  • Restructured the JavaScript code to comply with YUI style suggestions and to make a clean pass at www.jslint.com. This makes for better less error prone code.
    • The major change here is changing all function names to camelCase.
    • Moved the Cookie and Console objects inside the SWFUpload object.
  • Cleaned up some additional logic
  • Created a function this.DebugMessage(msg) to replace all the if (this.debug) Console.Writeln(msg);. Which does the same thing but gets ride of the all ifs and allows for easier changes to debugging in the future.
  • Added a ChangeLog.txt file and removed the 100 lines of comments from the top of the swfupload.js file.
Hopefully these changes will improve my code consistency, make the code easier to read, and make it more compatible with other JS libraries.

I recommend using the full blown swfupload.js for development but then using jsmin to reduce the file from 27 KB to 16 KB.

The demo swfupload.swf also has not had any of the "This script is running too long" patches applied to it. I have not, personally, had any of these errors come up but you may want to apply the patches anyways.

I've decided it's time to learn JavaScript and have started with the resource at http://javascript.crockford.com/ which are very good and reasonable. Hopefully my understanding and coding of JavaScript will improve ;)

16 comments:

  1. egbert023:04 PM

    Hi!

    Thanks for your great work! I really appreciate it. Your version is much better than the original one.
    I've noticed a small (but relevant) shortcoming of the software though (this applies to both your and the original version): The progress bar and the actual upload are not synchronous. If you upload a small file this is not very apparent, but if your upload a larger file (e.g. 5 MB) you notice it easily.
    The progress bar is at 100% after a few seconds (at most), the actual upload might take further minutes.
    Looks almost like some kind of caching-problem (or whatever) to me (don't know if servers are capable of caching incoming files).
    Any ideas how to fix this?
    Many thanks in advance!

    Egbert02

    ReplyDelete
  2. metro2:42 AM

    I was wondering whether you have any demos in asp.net (version 2.0 if possible) and if you do, where I could download them. Thank you very much :)

    ReplyDelete
  3. Is it possible to send the url params as POST vars?

    ReplyDelete
  4. @metro. I don't maintain any Asp.Net demos. I had some several revisions ago but I can't host them. Someone offered some PHP hosting so I switched to PHP.

    SWFUpload is language agnostic. The only bit that you have to worry about is the upload target. This page should accept a file upload and process it. It's not really any different than a regular ASP.Net upload page. The file will be found in Request.Files["Filedata"].

    @michael: Unfortunately the Flash Player (the bit that makes this all possible) does not give us any control over what data is sent. We can't manipulate the post data. The best we can do is send url params. I recommend against using too many url params (I only send the session id). You have to carefully encode them and different servers will treat them differently.

    ReplyDelete
  5. egbert021:02 PM

    Hi!

    I found the reason for the strange behaviour described above. It has nothing to do with SWFUpload (fortunately). It's the fault of Kaspersky Anti-Virus which I'm using at the moment.
    I disabled it (more or less by chance) and SWFUpload worked like expected. I enabled it again and the problem came back.
    Really strange...

    Egbert02

    ReplyDelete
  6. I've come across a few instances of this happening:

    1. If the script does a lot of process it happens after the file is uploaded. I see this when creating thumbnails of images. The SWFUpload hits 100%, stalls while the script makes the thumbnail and then fires fileComplete.

    2. I am behind a proxy server. The proxy intercepts the upload (a 600MB file uploads in 2~3 seconds). SWFUpload stalls at 100%. The proxy server makes the upload to the server (which takes the normal amount of time) and then SWFUpload fires fileComplete.

    I worked around this (a bit) by having the fileProgress event check to see if the file has reached 100% and then displaying a message that says "Processing file" so the user doesn't feel like the application has stalled.

    I'll bet the anti-virus software is doing the same kind of thing as the proxy server. It accepts the file, checks it for viruses and then uploads it. All SWFUpload sees is that the file has been accepted. It doesn't know it has been intercepted in the middle.

    ReplyDelete
  7. Hi,

    I think your version is really cool that I could make my customized UI and make it easily to control. Thanks by the way.

    And also, I actually found an minor problem. That is the setting fileTypes, it works for the file mask of file dialog, but when I try to key *.* in the file dialog, and select some type of files (that I don't allow), there is no error triggered, even thougth I could check by the fileObject.name to cacnel the file queue.

    ReplyDelete
  8. I noticed that too. But when I tried to upload a file with an invalid extension it actually crashed my browser.

    I'll have to add some checks in the next revision.

    In Revision 6 I am switching to ActionScript 3 and FlashPlayer 9. ActionScript 3 will allow us to get data back from the file upload, fixes some issues with invalid uploads (causes lots of problems and Macs), hopefully improves the 'cookies' bug and I hope to include Adobe's Flash detection script and automatic upgrade features.

    But we'll see.

    ReplyDelete
  9. Hazelnut7:18 AM

    That's sound very cool!!! Looking forward to version 6.
    Keep up the good work!

    ReplyDelete
  10. Jake,

    Thanks for the great contribution. I'm noticing the script/Flash crashing my browser at times. It happens when I cancel the file dialog (FF and Safari) and sometimes when I select a file in Safari.

    Any ideas?

    Thanks

    ReplyDelete
  11. Thanks Jake, for your great work. I'm using R52 in my Drupal upload module. I am just wondering if SWFUpload supports simultaneous uploads without having to instantiate multiple copies of swfupload.swf.

    Thanks again.

    ReplyDelete
  12. @i go by ed
    I've had crashes like that in FF on Linux. I suspect bugs in the Flash Player, which means, there probably isn't anything I can do. Also, this is a hobbyist side project and even though I'd like it to work perfect for everyone I don't have the resources to worry about it. So the source is provided and if you solve the problem it'd be nice to hear how!

    @nathan tran
    I wondered the same thing. I had thought about trying multiple simultaneous uploads but never really got time. Maybe I'll give it a go in Revision 6 (which is coming along nicely but slowly). I don't see why it couldn't work unless Flash just doesn't support it.

    ReplyDelete
  13. Jake, first off thanks! Nice mod of an already nice util. Before I saw that you are already at work on v6, I set about converting you r5 to AS3 because I really wanted to have access to the Server Side Code's response. I have it almost all working but got hung up on one point. Thought we might share notes and maybe I could even give you a hand.

    ReplyDelete
  14. I decided that that was important enough, as well, to move to AS3.

    I've got r6 mostly done. I attempted to repair the Firefox/Flash Cookie issue but even AS3 won't let you send cookies with a file upload. Silly me, not thinking I ripped out all the cookie passing features I had in r52. I need to add those features back in and it'll be about ready.

    I was able to add the ability to send additional post values in AS3 as well. I'll probably build an option to submit a form along with the upload.

    I've had some time constraints (and a vacation) over the last few weeks and haven't quite finished up r6.

    Shoot me an email at (o t i j i m _a_t_ y a h o o _d_o_t_ c o m) and I'll see if I can give any pointers. I'm just scraping along with the Adobe LiveDocs and Google so...ymmv ;)

    ReplyDelete
  15. Anonymous1:55 AM

    Hey, i often notice that on Mac/Linux the first file is not recognized and not uploaded.
    For example, if i open the page the first time and select a file to upload, it doesn't select it (it dosnt even call the upload-script) but on windows everything seems to be correct. Do you know such an error?

    ReplyDelete
  16. Anonymous2:42 PM

    I found this site using [url=http://google.com]google.com[/url] And i want to thank you for your work. You have done really very good site. Great work, great site! Thank you!

    Sorry for offtopic

    ReplyDelete