tags:

views:

14

answers:

1

I have a download function that I got from Andy Matthews, and an sd Card function that I got from Christian Cantrell. Now I need to download to the sd Card.

Q: How do I specify that storage = e.storageVolume.rootDirectory.nativePath?

var remoteFile = 'http://www.CompanyName.com/ClientName.txt';

jQuery(function($){
    air.StorageVolumeInfo.storageVolumeInfo.addEventListener(air.StorageVolumeChangeEvent.STORAGE_VOLUME_MOUNT, onVolumeMount);
    air.StorageVolumeInfo.storageVolumeInfo.addEventListener(air.StorageVolumeChangeEvent.STORAGE_VOLUME_UNMOUNT, onVolumeUnmount);

    var PluggedIn = false;
    var volumes = air.StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();
    for (var i = 0; i < volumes.length; i++) {
        if (volumes[i].isRemovable) {
            if (volumes[i].name == 'COMPANYNAME') {
                PluggedIn = true;
                $('#content').append('I see you already have CompanyName plugged in!');
                var myNativePath = volumes[i].rootDirectory.nativePath;
                var storage = 'desktopDirectory'; // myNativePath
                downloadFile(remoteFile, storage);
            } else {
                $('#content').append('What you have plugged in is not CompanyName.');
            }
        }
    }
    if (!PluggedIn){
        $('#content').append('<h1>Please insert your CompanyName card.</h1>');
    }

})

function onVolumeMount(e) {
    if (e.storageVolume.isRemovable) {
        $('#content').html('<h1>Thank you</h1>');
        if (e.storageVolume.name == 'COMPANYNAME') {
            var myNativePath = e.storageVolume.rootDirectory.nativePath;
            var storage = 'desktopDirectory'; // myNativePath
            downloadFile(remoteFile, storage);
        } else {
            $('#content').append('<p>The card you just plugged in is not CompanyName.</p>');
        }
    } else {
        $('#content').append('<p>This device is not removable</p>');
    }
}

function onVolumeUnmount(e) {
    $('#content').html('<h1>Goodbye!</h1>');
}

function downloadFile(remoteFile, storage){
    var fn = remoteFile.match(/[a-z0-9-+\._]+?$/i);
    var myFile = air.File[storage].resolvePath(fn);
    var myURLStream = new air.URLStream();
    myURLStream.addEventListener(air.Event.COMPLETE, function(e){
        var myByteArray = new air.ByteArray();
        myURLStream.readBytes(myByteArray, 0, myURLStream.bytesAvailable);
        var myFileStream = new air.FileStream();
        myFileStream.openAsync(myFile, air.FileMode.WRITE);
        myFileStream.writeBytes(myByteArray, 0);
        myFileStream.close();
    });
    myURLStream.load(new air.URLRequest(remoteFile));
}
A: 
var myFile = new air.File("file:///" + storage).resolvePath(fn);
cf_PhillipSenn
http://forums.adobe.com/thread/240134
cf_PhillipSenn

related questions