views:

51

answers:

2

I'm looking for an AS3 function to get the filesize of a file that is being hosted on a remote webserver. Tried to find some functions but didn't succeed. Maybe somone can help me ?

A: 

Try to use URLStream class. It has bytesAvailable property. It should return a number of available bytes to download

Laserson
In most cases, the streaming will fail to start due to security policy issues.
Amarghosh
+1  A: 

You can't do this directly through ActionScript. You would need to make a request to download the file before you can get the size of the file. Once the download request has been made you can get the total number of bytes of the file through the LoaderInfo class. Obviously this has the undesirable side affect that the file continues to download.

Two solutions... one have an xml file on the server that contains the size of the files (if done manually this is a real pain in the ass, as file sizes are very prone to change).

You could have some sort of server side solution that you could make requests to to get the size of a particular file. Or have it setup to generate xml for the file sizes of all you files. There are probably numerous server side solutions. With it not being my area of expertise i can't really recommend the best approach.

My view is that it's rarely worth the bother. There's normally a design decision you could make to avoid having to retrieve this kind of info. That said there could be a valid reason that warrants the server side work.

James Hay
another issue with trying to download is that most of the times the request will fail due to lack of policy file, which makes sense too.
Amarghosh
If you have access to the server you can add policy files that will allow access to content from a particular location. This is extremely common.
James Hay
If one has access to the server, then he should do it at the server side as you suggested. Loading and canceling it after getting file size doesn't sound like a good idea.
Amarghosh