Tuesday, April 24, 2007

SWFUpload R5 Release!

I'm happy to announce the release of SWFUpload R5 (my heavily modified version of the original SWFUpload).

I'm also pleased to announce that Tarkheena has graciously provided hosting for the SWFUpload R5 demos and downloads.

And a final thanks to Lars and the SWFUpload team. They have created a great upload control and it's been great expanding on their work.

SWFUpload R5 New Features and Changes
  • Tested and Fixed the automatic cookie passing feature. It works now.
  • Switched to PHP for the demo format.
  • Switched from Flash Studio 8 to FlashDevelop. This is an Open Source Flash IDE that works great. I seem to have been able to work around the bugs found when SWFUpload v1.0.2 moved to FlashDevelop. This move allows anyone to modify the SWF file. Not just people who can afford Adobe's Flash Studio.
  • Greatly improved the callback system. You no longer pass in a string with the function name to the settings. Now you pass in the actual Function reference. This gets rid of the flashReady_callback handler, which always felt wrong, and makes more advanced things possible with multiple instances. This also allow the this object to refer to the SWFUpload instance inside the Event Handlers.
  • Renamed just about everything to make the settings and functions more consistent and clear. Replaced the -XX error codes with names and other such niceties.
  • File Selecting is now subject to the FileUploadLimit. E.g., if the upload limit is 10 and the user attempts to queue 11 files then an error is thrown. Or if the file has queued 10 files and attempts to queue 1 more then an error is thrown.
  • Returns a sensible error when Zero Byte files are uploaded.
  • You can change the UploadTargetURL at anytime using the SetUploadTargetURL function.
  • Improved the SWF to Javascript debugging.
  • Improved the encoding of strings.
Demos and Download

You can try out the demos and download the source at http://swfupload.praxion.co.za/index.php

Please note: there is a 2MB upload limit on this server regardless of what SWFUpload allows. I'll see if I can get this fixed soon

Thursday, April 12, 2007

Destroying ASP.Net with an IFRAME

Today, while implementing a "Thank you after download" page using the iFrame method, my page suddenly began throwing ArgumentExeption: Invalid postback or callback argument. I could not, for the life of me, figure out what was causing it.

I wasn't doing anything funny with any server-side controls and the page had been working just fine before I added the download code.

I turns out that I was using some HTML like this:

<iframe src="http://website.com/download" style="display: none;" />


Which is perfectly acceptable XHTML (as far I've bothered to find out). But ASP.Net has a conniption. You have to format it like this:

<iframe src="http://website.com/download" style="display: none;"></iframe>


So there you have it. If you don't use a closing tag on an iFrame in ASP.Net 2.0 it will throw a fit and you'll spend hours wondering what is going on.

How To: Redirect After Download

Don't!

I don't think you can. I googled a bit and gave up. Then I decided to check a page where I've seen it done: Source Forge. Turns out that they cheated!

So, the answer is still "don't", however, we can do what SF does and...fake it!

What I want to happen:
  1. Our user sees a link to a download and clicks it.
  2. The Save As... dialog appears and the user selects the location.
  3. The browser displays a "Thank You" page while the download finishes in the download window.

How to Fake it:
  1. Our user sees a link to a download and clicks it.
  2. The link takes the user to the "Thank You" page. The "Thank You" has an iFrame whose src attribute is the real download link.
  3. The Save As... dialog appears and the user selects the location.
  4. The download finishes while the user views the "Thank You" page.

Discussion:

There could be compatibility issues with an iFrame in mobile or really old browsers. Some alternatives might be:
  • Use a <meta> tag refresh pointing to the real download link and a time of 0 (zero).
  • Try a Javascript redirect.
But the idea is to fake it by displaying the "Thank You" page first and then starting the download.

If all else fails just rethink your download flow. The user clicks the download link. He gets the "Thank You" page which has a very clear, front and center link that says "Begin Your Download by clicking here" or something that says "I'm really sorry you have to click twice (it's not my fault you use a lame browser) so please accept this flattering compliment (to help avoid the total destruction of the world (and I'm sorry your self-esteem is so fragile))."

Monday, April 02, 2007

SWFUpload R4 Update Release

I've fixed a couple of issues and added some features to SWFUpload Revision 4.

  • Cleaned up the code. Removed unused code. Added more error checking. Added more comments. (Both Javascript and ActionScript)
  • Removed create_ui feature that would add a link to queue up files. The feature was too incomplete to bother with. You should build your own UI and use the ui_target, degraded_target and the callback handlers to display updates.
  • Added the upload_backend_cookies setting to help with a Windows Flash/Firefox bug. It accepts a cookie name (or an array of cookie names) that will be added to the upload_backend url (if the cookie is found). This assists with passing ASP.Net Auth tickets or PHP Session IDs. Why you would want to do this is described on the SWFUpload forums. *This feature is untested.
  • Implemented a workaround for an IE bug where a Flash Movie placed inside a FORM cannot make callbacks to JavaScript (source). You can now place the flash_target in the form if you want. You might still have problems adding a Flash Movie to a form if don't use the Window.Onload event.
  • Renamed the class to SWFUpload from mmSWFUpload.
  • Did some more sprucing up of the demos.
Feel free to download SWFUpload R4.1.

I would really appreciate feedback on issues, bugs, and any other questions or successes you might have.

If anyone would like to host the demos please let me know. I've given up on free hosts and am not currently in a position to purchase hosting.