Dropping remote files

Adobe AIR 2 and later

Use the URLFilePromise class to create file promise objects representing files or data available at a URL. Add one or more file promise objects to the clipboard using the FILE_PROMISE_LIST clipboard format. In the following example, a single file, available at http://www.example.com/foo.txt, is downloaded and saved to the drop location as bar.txt. (The remote and the local file names do not have to match.)

<html> 
<head> 
<script src="AIRAliases.js"></script> 
<script src="aircore.swf" type="application/x-shockwave-flash"></script> 
<script language="javascript"> 
    function init(){ 
        var source = document.getElementById('source'); 
        source.addEventListener("dragstart", dragStartHandler); 
    } 
     
    function dragStartHandler(event){         
        event.preventDefault(); 
        startDrag(); 
    } 
    function startDrag() 
    { 
        var filePromise = new air.URLFilePromise(); //defined in aircore.swf 
        filePromise.request = new air.URLRequest("http://example.com/foo.txt"); 
        filePromise.relativePath = "bar.txt"; 
        var fileList = new Array( filePromise ); 
        var clipboard = new air.Clipboard(); 
        clipboard.setData( air.ClipboardFormats.FILE_PROMISE_LIST_FORMAT, fileList ); 
        air.NativeDragManager.doDrag( window.htmlLoader, clipboard ); 
    }     
</script> 
</head> 
<body onLoad="init()"> 
    <p id="source" style="-webkit-user-drag:element; -webkit-user-select:none;"> 
        Drag to file system 
    </p> 
</body> 
</html>

You can allow the user to drag more than one file at a time by adding more file promise objects to the array assigned to the clipboard. You can also specify subdirectories in the relativePath property so that some or all of the files included in the operation are placed in a subfolder relative to the drop location.

The following example illustrates how to initiate a drag operation that includes multiple file promises. In this example, an html page, article.html , is put on the clipboard as a file promise, along with its two linked image files. The images are copied into an images subfolder so that the relative links are maintained.

<html> 
<head> 
<script src="AIRAliases.js"></script> 
<script src="aircore.swf" type="application/x-shockwave-flash"></script> 
<script language="javascript"> 
    function init(){ 
        var source = document.getElementById('source'); 
        source.addEventListener("dragstart", dragStartHandler); 
    } 
     
    function dragStartHandler(event){         
        event.preventDefault(); 
        startDrag(); 
    } 
    function startDrag() 
    { 
        var filePromise = new air.URLFilePromise(); 
        filePromise.request = new air.URLRequest("http://example.com/article.html"); 
        filePromise.relativePath = "article.html"; 
     
        var image1Promise = new air.URLFilePromise(); 
        image1Promise.request = new air.URLRequest("http://example.com/images/img_1.jpg"); 
        image1Promise.relativePath = "images/img_1.html"; 
        var image2Promise = new air.URLFilePromise(); 
        image2Promise.request = new air.URLRequest("http://example.com/images/img_2.jpg"); 
        image2Promise.relativePath = "images/img_2.jpg"; 
         
        //Put the promise objects onto the clipboard inside an array 
        var fileList = new Array( filePromise, image1Promise, image2Promise ); 
        var clipboard = new air.Clipboard(); 
        clipboard.setData( air.ClipboardFormats.FILE_PROMISE_LIST_FORMAT, fileList ); 
        air.NativeDragManager.doDrag( window.htmlLoader, clipboard ); 
    }     
</script> 
</head> 
<body onLoad="init()"> 
    <p id="source" style="-webkit-user-drag:element; -webkit-user-select:none;"> 
        Drag to file system 
    </p> 
</body> 
</html>

// Ethnio survey code removed