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.