« Exhaustive List of Everything That's New in AIR 2.0 | Main | Some Interesting AIR Marketplace Statistics »
October 30, 2009
A Screencast Explaining and Demoing File Promises
File promises are kind of a difficult concept to describe, so I decided to explain them using a video. Hopefully this clarifies what file promises are, and why it's such a cool new feature of AIR 2.0:
Here's the code that creates a URLFilePromise for every file to be downloaded and puts them on the clipboard. But first, some code context:
onDragStartis the event handler that gets called when the user starts dragging items from the list of objects.bucketListis the ComboBox of bucket names.objectListis the DataGrid of objects.- The function
s3.getTemporaryObjectURL(...)generates a temporary public URL that points to the specified object. It's the URL that theURLFilePromisewill use to access the file.
private function onDragStart(e:DragEvent):void
{
if (bucketList.selectedIndex == 0 || objectList.selectedItems == null) return;
var c:Clipboard = new Clipboard();
var items:Array = objectList.selectedItems;
this.filePromises = new Array();
for each (var item:Object in items)
{
var fp:URLFilePromise = new URLFilePromise();
var req:URLRequest = new URLRequest(s3.getTemporaryObjectURL(bucketList.selectedItem.name, item.key, 60));
fp.request = req;
fp.relativePath = item.key;
this.filePromises.push(fp);
}
c.setData(ClipboardFormats.FILE_PROMISE_LIST_FORMAT, this.filePromises);
NativeDragManager.doDrag(objectList, c, null, null, null);
}
Below is the function that gets called when the drop is complete. It's responsible for opening the ProgressWindow component and passing it the array of URLFilePromise objects which the ProgressWindow component hooks into in order to receive progress events.
private function onDragComplete(e:DragEvent):void
{
var progressWindow:ProgressWindow = new ProgressWindow();
progressWindow.open(false);
progressWindow.setFilePromises(this.filePromises);
}
The code for S3E is open source and available on Google Code.
Posted by cantrell at October 30, 2009 6:11 AM
Comments
ah, ok. now i get what file promises are. thanks for the explanation. is this a common term used, or did you guys make this up?
Posted by: sean at November 5, 2009 5:57 AM
@Sean: "File Promises" is a term that we got from OS APIs. We didn't come up with it ourselves. You can read more here (scroll down to the "File Promises" section):
Posted by: Christian Cantrell at November 5, 2009 6:09 AM