开发者

Get filesize of remotely hosted file

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 s开发者_StackOverflow社区omone can help me ?


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.


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


thanks for the tip, it works just great. See the example below

var httpStream:URLStream =  new URLStream();
httpStream.load(httpRequest);

httpStream.addEventListener(    Event.COMPLETE,
                function(e:Event):void{
                                                  trace(httpStream.bytesAvailable);
                            });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜