When an upload is successful uploadSuccess is called with the returned server data. However at the server side I need to do some processing on the uploaded file which can take > 10 seconds to complete, during that time I have no way to communicate to the user what's going on. Is there a way to get output from the server as soon as it arrives (instead of getting the data all at once)?
February 27, 2009 - 10:27am
Flash does not provide us a way to get the server output in real time. It waits until the response is complete and then sends everything in one shot.
February 27, 2009 - 12:00pm
... takes more than 10 seconds? Are you scanning the files completely for information - perhaps with getid3 - this is what I am thinking of. Or are the files so huge?
Perhaps I misinterpret everything: a) file is uploaded with flash, so once uploaded you'll receive the completed signal. b) post-processing is handled AFTER that, so maybe you can write some ajax at the start and at the end of post-processing indicating that there is something still going on.
Longest time for post-processing I experienced so far was below 2 seconds.
February 27, 2009 - 3:59pm
SWFUpload (Flash) waits until the server finishes the response before it calls uploadSuccess. If your script processes the upload for several seconds SWFUpload waits.
You can see this in the Application Demo. The file progresses. When we hit 100% we have uploadProgress say "Creating Thumbnail". Then SWFUpload waits. We've found that Flash will only wait 30 seconds and then silently fails. Anyhow, once the upload.php finishes (which can take a few seconds) it sends the response and SWFUpload fires uploadSuccess.
You can test this behavior by putting sleep(20) in upload.php. You'll see that there is a 20 second delay between the last uploadProgress and uploadSuccess.
What we have done is a secondary progress indicator. We do the progress bar for the upload then display a message with a spinner saying "processing file". Then when uploadSuccess fires we indicate that we've finished.
All we have to do is check for 100% complete in uploadProgress to know when we're ready to display the spinner.