# Download files to application directory

**URL:** https://forum.kirupa.com/t/download-files-to-application-directory/263625
**Category:** Uncategorized
**Created:** [June 17, 2008, 7:37pm UTC](https://forum.kirupa.com/t/download-files-to-application-directory/263625 "2008-06-17T19:37:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Tim\_John](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@Tim\_John](https://forum.kirupa.com/u/Tim_John)
#### Post date: [June 17, 2008, 7:37pm UTC](https://forum.kirupa.com/t/download-files-to-application-directory/263625/1 "2008-06-17T19:37:48Z")

</div>

Eek, I made a rather stupid assumption with AIR, and it seems I may be wrong.

I thought that AIR was able to download files (in my case mp3 files) from a http server and store them in the application storage directory without any user interaction. Essentially it’s a flash program that automatically retrieves podcast files from an RSS Podcast feed for visitors of a gallery to peruse. The machine won’t be online all the time, so offline local backup of the files is necessary. And a dialogue box popping up for vsitors to mess around with must be avoided.

Is this possible or have I just signed my own death warrant? Please don’t make me go back to Zinc!!!

---

<div class="post-metadata">

### Author: ![Rezmason](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rezmason/32/30447_2.png) [@Rezmason](https://forum.kirupa.com/u/Rezmason)
#### Post date: [June 18, 2008, 2:54am UTC](https://forum.kirupa.com/t/download-files-to-application-directory/263625/2 "2008-06-18T02:54:59Z")

</div>

It should be possible to save stuff to application storage, but note the difference between the application directory and the application storage directory- the app directory cannot be edited, while app storage can.

Use URLLoader to grab a file’s bytes off the intertubes. Then use the filesystem classes to write the bytes to a file in app storage. I can try this out personally if you want.

---

<div class="post-metadata">

### Author: ![Rezmason](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rezmason/32/30447_2.png) [@Rezmason](https://forum.kirupa.com/u/Rezmason)
#### Post date: [June 18, 2008, 4:42am UTC](https://forum.kirupa.com/t/download-files-to-application-directory/263625/3 "2008-06-18T04:42:06Z")

</div>

Here we go. Simple example, takes an mp3 off of Flashkit and sticks it in the application storage directory. This code can go right in the timeline.

```auto
import flash.filesystem.*;

var url:String = "http://downloads.flashkit.com/loops/Techno-Dance/Techno/Cheap_Ga-Osnoff-8749/Cheap_Ga-Osnoff-8749_hifi.mp3";
var urlRequest:URLRequest = new URLRequest(url);
var urlLoader:URLLoader = new URLLoader();

urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Event.COMPLETE, proceed);
urlLoader.load(urlRequest);

function proceed(event:Event):void {
	var bytes:ByteArray = urlLoader.data;
	var file:File = File.applicationStorageDirectory.resolvePath("./gotit.mp3");
	var filestream:FileStream = new FileStream();
	
	filestream.open(file, FileMode.WRITE);
	filestream.writeBytes(bytes);
	filestream.close();
}

```

---

<div class="post-metadata">

### Author: ![Tim\_John](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@Tim\_John](https://forum.kirupa.com/u/Tim_John)
#### Post date: [June 18, 2008, 8:21pm UTC](https://forum.kirupa.com/t/download-files-to-application-directory/263625/4 "2008-06-18T20:21:29Z")

</div>

Thank you very much Rezmason. I was wondering if it could be done this way, but was getting a bit worried about how to actually do it and whether it would work or not, but it’s working a treat! Cheers.
