Flash FileReference, Uploading Larger Files, “A script in this movie is causing Flash Player to run slowly”
Tagged as: FlashI realize my post titles may seem strange but I'm trying to make them as search engine friendly as possible.
With the advent of Flash 8 came file uploading capabilities. At the time we really weren't doing anything that had a calling for this lovely new capability. There were instances in the past where it would have been great, we tried all the tricks everyone else had and boy was it painful. Thankfully Macromedia listened and hooked us up! I love it when they do that.
Earlier this year the call came in and we needed the ability to upload video files from a Flash front end for a contest. Great! I said to myself, my boy Flash can do this. I skimmed the docs, prototyped a little test application and pushed it up to the server. Set the permissions on files and folders and we were ready to go!
The docs tell you that your supported up to around 100mb. Perfect, we have a 50mb cutoff for the videos, let's run some tests. Fire up the ole busted G4 or "Sweetness" as I call her and head back to the PC to start testing as "Sweetness" needs some serious ramp up time. Let's start out small, we'll upload a 3-4 mb file and see how it goes. Beautiful, all event handlers are firing, progress bar is functioning, complete event is called and the file is in the designated folder on the server ready to get worked.
Let's kick it up a notch and grab a 40mb file, we'll also fire up NetLimiter so we can bog down our connection a little bit. Start the upload and go grab a coffee. Upon returning i'm greeted with an error dialog I have only read about, I actually thought it was a myth:
"A script in this movie is causing Flash Player to run slowly"
Strange indeed, this is a bare bones prototype, no code outside of the FileReference event handlers other than a button that allows you to select a file and a progress bar that scales based on percentage up.
Let's see what sweetness has to say about this...
She's bombing in Safari on the 3-4mb file!
Turn off NetLimiter and re-try the 40mb file. File get's upped in a few minutes, no error messages. Rinse and repeat about 20 more times trying various sizes and speeds. Sometimes it generates an error sometimes it doesn't. Mind boggling to say the least. Mind you this isn't an IO, Security or HTTP Error, all server settings are proper, files and folders have rights, PHP is set to well over 500MB. It's just strange as it actually does go through sometimes.
Google searches return nothing, I found a few complaints about the same scenario but no one seems to have found a fix.
Adobe's KB article tells you it's a problem with the application, pointing to loading large amounts of data or manipulating large amounts of data and that the user might think the application is unresponsive. As with any downloading or uploading from within Flash you should always provide status to the user and I think most do. What I'm experiencing here doesn't seem to fall into this category though as users connection rates vary, this doesn't seem fair, why didn't they think about this?
So if Flash seems to think my simple prototype is unresponsive because it's taking too long to upload a largish file, then I need to give Flash some busy work while this is happening, in the form of a simple EnterFrame.
So now when we fire the FileReference.upload method we call another method that just increments an integer by 1 within an EnterFrame. Also we need to kill this process onComplete, onCancel and onAnyError.
Simply put, we need to startSomeNonsense and endSomeNonsense when we need to upload in Flash just to be safe. I'm also going to assume this is similar for the "download" portion of FileReference.
function startSomeNonsense var count:Number = 0; this.onEnterFrame = function(){ count += 1; } } function endSomeNonsense delete this.onEnterFrame; } file.upload("file.php") startSomeNonsense();
This seemed to get rid of the error dialog messages on all browsers and platforms ( mac / pc ) tested no matter what the transfer rate was, and this made me happy.
Note, this was tested with Flash Player 8 and early versions of Flash Player 9. Has not been tested with the latest version of Flash Player 9.
Hopefully this helps someone else in the future.