Thursday, May 03, 2007

SWFUpload Revision 5.2 Release

Edit: If you downloaded R5.2 before May 4th you should download again. I made some minor fixes that I missed:
  • Zero file size limit fixed to mean unlimited
  • Default flash width/height set to 1px to work better in Linux (also default color set to #FFFFFF since it is visible in Linux.
/Edit

Alright. I've completed another overhaul and feature creep cycle in the SWFUpload Revisions. I'm going to have to take a break for awhile. It's time to get back to work (real work I mean).

Revision 5.2 includes updates to several features, improves the internal processing of the files and takes care of some bugs that I missed because of insufficient testing.

Changes
  • Out of Order file uploads now possible.
  • Per file upload parameters (these are added to the upload target query string. These are also passed to JavaScript with the fileObj).
  • Dynamic modification of cookie and custom parameters (fixed so cookies aren't wiped out when updating other settings).
  • Added a Queue Limit. E.g. Use if you only want users to queue and upload one file at a time you can set the queue limit to 1.
  • Added a QueueStopped event (change from throwing a FileQueued event when the upload was stopped).
  • Fixed the various limits so setting them to zero means unlimited.
  • Added a ui_function setting that allows you to specify the function to call instead of _showUI. This gives you the power to do whatever you want with the UI after SWFUpload has completed loading without having to modify the SWFUpload javascript files.
  • Created a "Features" demo that lets you tweak (almost) all the settings in SWFUpload R5.2 and test it without having to fiddle in the code.
  • ActionScript modifications:
    • Changed from using an ever growing array to track each queued file to a FIFO queue. This simplifies the code in a lot of ways.
    • Wrapped the FileReference object in a custom FileItem object which allows per file parameters and better abstraction.

The Revisions website has been update: http://swfupload.praxion.co.za/index.php

Another big thanks to Tarkheena for providing the great hosting!

Additional Notes

I've been having all kinds of trouble with UTF-8 encoding and byte headers. I tried to get the encoding consistent but may have missed some files. Incorrect encoding has caused issues ranging from PHP errors to JavaScript files not loading. Let me know if there are any problems.

There was a report that SWFUpload R5 (and probably R5.2) does not work under Firefox 1.5 in Linux. I plan to test and hopefully fix this soon.

I tested R5.2 in Ubuntu 6.10 on Firefox 2.0. I fixed a couple small issues that prevented SWFUpload from loading (see Edit above). I noted that it seems like FileProgress events are not called very often. Also, Stopping or Cancelling causes a crash. If you are targeting Linux users you should include JavaScript that detects the Linux Flash Player and prevents these actions. I don't plan to add this kind of detection to my code.

I can create a browser crash in both IE and Firefox on Windows XP SP2. While I have the File Dialog open, I force a page change (reload or move to a different url). I happened on this when I was using <input type="submit" onclick="suo.Browse()">. The File Dialog would open but then the form would submit and change pages. The browser would crash as soon as I clicked Open or Cancel.

18 comments:

  1. could you elaborate on "Out of Order file uploads now possible." - what does it mean?

    I mentioned a bug request on the original SWFupload forums, but development seems to have stopped there - can your library upload a single file of the queue, then do a callback, and continue to the next file after a 1ms pause?
    The reason I ask that, is that I want to make a progress meter, but it's difficult to do when all the callbacks come at once (as happens in SWFUpload, in Firefox, in Linux)

    ReplyDelete
  2. Out of order uploads means after a set of files are queued you can pass a File ID to StartUpload(file_id) and only that file will be uploaded. If you do not pass in anything the queue is started. If you pass in a file_id that can't be found then nothing happens. You can test this in the Features demo.

    I hadn't heard of the callback issue in Linux. My own (very limited) testing didn't show anything like that.

    However, using the out of order uploads you could use JavaScript to build your own queuing routine that makes a delay between each upload.

    ReplyDelete
  3. In my testing in Ubuntu and FF 2.0 I noticed that I only get one or maybe two FileProgress callbacks. These event callbacks are made by the Flash Player and are completely out of my control.

    I am operating behind a authenticating proxy, however, and that also causes weird things for me (like a 128MB file appears to upload in a couple seconds but never actually uploads to the server, just the proxy).

    I've got hold of a slightly old laptop and managed to get Ubuntu 7.04 installed and the wireless card working just this morning. I plan to do more testing on Linux in the near future.

    After re-reading your progress meter explanation I'm starting to feel like I'm not quite sure what you are after and I'm not sure what a 1ms pause between the finishing of one file and the start of another accomplishes.

    ReplyDelete
  4. I'll explain further, although I think you've solved it with that out of order thing.

    in Firefox, if you have a load of DOM changes (for example, changing a progress meter) that are done without pause through JavaScript, the browser will not show the changes until the script finishes running and it is given a moment to catch up.

    This affects SWFupload, because the upload appears to be synchronous - it acts like one big blocking thread which stops the browser from showing any DOM changes until it has finished all of the uploads. (I could be wrong, but this is how it appears)

    With your "out of order" upload, it is possible to give the browser its breathing space so it can display any DOM changes we've asked it to do during the upload.

    I'll replace my copy of SWFupload with your updates in KFM (http://kfm.verens.com/), and see if your solution fixes my problems. I suspect it will.

    ReplyDelete
  5. Hi... Thanks for the revision.
    I have a question. Can I just use the classic form as it is but with no limit on file uploading?

    ReplyDelete
  6. @jacob: Sure you can. You can build any UI you want around the SWFUpload control. So, for the classic form, if I wanted to allow unlimited uploads I'd just change the file_upload_limit and the file_queue_limit to zero.

    This allows the user to queue as many files and required. When the "submit" button is clicked all the files will upload and then the form (separately) submitted.

    ReplyDelete
  7. Jacob3:03 AM

    @jake
    Thanks for the tip...
    I just found out swfupload two days ago and i don't know very well how it works.
    I have a form with a filefield and i want apply swf in that field in order to upload multiple files. When i press the submit button it as to move the files to a folder and save the references in the mysql references so that i may use recordset...
    If i paste you my html code would you help me to apply? Thanks... Sorry for the english. I'm from Portugal

    ReplyDelete
  8. Jacob5:52 AM

    @jake

    Can you take a look at:
    http://paste.lisp.org/display/40859

    The PDF input (line 163) is where I want to use SWFUpload.
    In line 50 I make the content move to folder ./img
    I need to do like in lines 52 to 61 so that I may use recordset...
    Can you give a hand?

    ReplyDelete
  9. To use SWFUpload it's a bit easier if you create another PHP file that handles the upload.

    You should refer to the Official Website forum for general SWFUpload help and tips about working around bugs. They do not support Revision 5 but you can get a lot of good information there.

    Then just download the demos and play around with them and figure out how SWFUpload is working.

    ReplyDelete
  10. Hello, I've just discovered your Revision 5.2 yesterday and looks great. I think I understand most of the JS parameters, but I don't understand the way to send "an answer" from PHP to the SWF when upload is completed. Can you put in some place the PHP code of your application demo to see how parameters must be sent from PHP and what are the possibilitties I have to handle?
    Thanks a lot!

    ReplyDelete
  11. Hi there, the current downloadlink is not working. Could you fix this? :)

    ReplyDelete
  12. Anonymous10:03 AM

    @terry: I just ran into the broken link as well. I haven't made sure the files are right yet, but it seems to work if you replace "swfupload_vr52" with "swfupload_r52" (removing the 'v') in the URL-

    ReplyDelete
  13. It should be fixed. Sorry about that, I run in to problems like this every time I do an update. I've got so much caching going on between me and the website (i.e., browser, proxy) I never know what is most up to date.

    On that note: If some of the demos don't work but they used to work try clearing your browser cache.

    I actually had to directly download the JS files to get them to uncache.

    ReplyDelete
  14. kornee10:51 PM

    Hi there!
    Thanks for the beautiful work, but - I have a problem integrating this script onto a server with php safe mode ON...
    I tried to use the application demo - and it looks like that everything is ok, but at the end of uploading each file, it pop-ups 403 or 500 error...

    Please, could anybody help me with that?

    ReplyDelete
  15. kornee12:22 AM

    oh, I forgot to tell you one little unimportant thing :) - that when i run the script test.php, the image uploads ok...

    I'm looking forward to your tips... thanks!

    ReplyDelete
  16. Anonymous4:48 AM

    hi,

    i can´t figure out how to add named url-parameters dynamicly...

    sfu.addParams(?????

    ReplyDelete
  17. @kornee: I don't know much about PHP safe mode. The application demo does have some issues (I get weird crashes in Linux, or it ignores the first upload) but I haven't had time to work them out. Flash in Linux is not stellar.

    403 error means "Forbidden". So the SWF is asking for the upload script and the web server says "No Way". 500 means Internal Error. Many of the scripts return 500 to indicate some kind of error occurred but the server could return 500 for any reason.

    However, if the test.php file works fine then my only guess is that maybe Flash is sending the HTTP Post in a format that PHP or the web server does not like.

    ReplyDelete
  18. @anon:

    You can see how this works in the features demo. It's about clear as mud but it is there.

    In order to set the upload parameters you use 'sfu.setUploadParams({param1: "value1", param2: "value2", paramN, "valueN"})'

    The features demo has an addParam function but that function just updates the select box. Look fro the "updateDynamicSettings" function. It gets the param Object {param1: "value1", param2: "value2", paramN, "valueN"} and uses setUploadParams to store the params object.

    After you set the params object you have to call "updateUploadStrings()" to tell SWFUpload to send the information to the Flash file.

    I know this probably isn't the "best way". Maybe in Revision 6 it will change. But it works well in most situations and prevents too many JavaScript to Flash calls which are kind of slow.

    ReplyDelete