views:

331

answers:

1

Flash 8 FileReference API gives you the possibility to check periodically for the number of bytes being transmitted:

listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
    trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
}

(more infos here and here)

In case of upload, would you suggest to use this method to check for the integrity of the uploaded file?

A: 

Just listen to the onComplete event to check whenever the file is properly uploaded. If no error events have been thrown so far the file should be on the server.

If you don't want to trust FlashPlayer regarding the integrety of the posted file (e.g. your server failed moving it from the /tmp folder, etc. ), something likely would be necessary to make sure the procedure was finished properly :

  • Check the file size (best would be checksum, don't think you can get that though) client side.
  • Post this information within the file upload request.
  • Once the post data received, gather the same information (size, checksum) server-side from the received file and compare it with the information generated client-side.
  • Send back status (fail/success)

... Unless your application is very sensible I would skip this though, just for the simple reason that it might generate more problems than if you hadn't got any integrity-check at all : )

Better: depending on the file you send you may be able to find out a server script to check if the file looks fine and just send back a status depending on that.

Theo.T