Downloading file parts with AIR
I just found out something cool using URLRequestHeaders in AIR.
Using the “Range” header, you can download specific part of a file.
var urlLoader:URLLoader = new URLLoader();
var urlRequest:URLRequest = new URLRequest("http://upload.wikimedia.org/wikipedia/commons/f/f2/Fanciful_Landscape-1834-Thomas_Doughty.jpg");
urlRequest.method = "GET";
urlRequest.requestHeaders = [new URLRequestHeader("Range", "bytes=0-99")];
urlLoader.addEventListener(Event.COMPLETE, loaded);
urlLoader.load(urlRequest);
function loaded(e:Event):void{
trace(e.currentTarget.data);
}
In this example above, it will load just the first 100 bytes of the file.
I don’t know if there is other ways to do it, but, at least it worked fine for me.
With this, you can manage downloads for huge files pausing and resuming not loosing datas.
Like, if the internet connection breaks while you are downloading something, you can simply resume after the internet connection comes back.
Luis said,
April 8, 2009 @ 3:01 pm
Are you sure this is working as you expected?, according to the documentation “Range” request header cannot be used among others:
http://livedocs.adobe.com/flex/gumbo/langref/flash/net/URLRequestHeader.html
keita said,
April 8, 2009 @ 6:26 pm
Hey Luis,
It works only with AIR, did you try it?
Swine flu. said,
May 3, 2009 @ 11:34 am
1975 swine flu vaccine and side effects….
Swine flu. Swine flu epidemic. 1976 swine flu scare. Swine flu shot. Swine flu deaths from shot. Reaction to swine flu vaccine….