View Full Version : Download files from server and save to user's computer - possible?

04-28-2008, 01:10 PM
Our client's website has a download area where users can log in and download images and 3D models in various formats of their products. I've been asked about the viability of porting this download area to an AIR application. Is this possible? Can an AIR application access files on a remote server and save them to the user's computer (in a directory specified by the user)? I've read the AIR white paper on security but am still unclear as to whether this can be done and how.

Thanks in advance!

04-30-2008, 12:07 AM
yes its possible.

use the URLLoader to load the necessary file in URLLoaderDataFormat.BINARY.
once that has loaded. just use the File and FileStream classes to save the file.

var byteLoader = new URLLoader();
byteLoader.dataFormat = URLLoaderDataFormat.BINARY;
byteLoader.addEventListener (Event.COMPLETE, onBytesLoaded);
var fileRequest = new URLRequest ("image.jpeg");
byteLoader.load (fileRequest);

function onBytesLoader(evt:Event){
var myFile:File = File.documentsDirectory.resolvePath("images/image.jpeg");
var myFileStream:FileStream = new FileStream();
myFileStream.open(myFile, FileMode.WRITE);
myFileStream.writeBytes(evt.target.data, 0, evt.target.data);

Am i the only person on here that answers AIR questions? lol

05-01-2008, 12:26 PM
Am i the only person on here that answers AIR questions? lol


05-01-2008, 03:48 PM


05-02-2008, 08:03 AM
Thanks a million, that's exactly what I was looking for.