Air 如何在空中下载到sd卡

Air 如何在空中下载到sd卡,air,Air,我有一个下载功能,我从,和一个sd卡功能,我从。现在我需要下载到sd卡上 问:如何指定storage=e.storageVolume.rootDirectory.nativePath var remoteFile = 'http://www.CompanyName.com/ClientName.txt'; jQuery(function($){ air.StorageVolumeInfo.storageVolumeInfo.addEventListener(air.StorageVol

我有一个下载功能,我从,和一个sd卡功能,我从。现在我需要下载到sd卡上

问:如何指定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));
}
var-remoteFile='0http://www.CompanyName.com/ClientName.txt';
jQuery(函数($){
air.StorageVolumeInfo.StorageVolumeInfo.addEventListener(air.storagevolumechangevent.STORAGE\u VOLUME\u MOUNT、onVolumeMount);
air.StorageVolumeInfo.StorageVolumeInfo.addEventListener(air.StorageVolumeChangeEvent.STORAGE\u VOLUME\u UNMOUNT,onVolumeUnmount);
var-PluggedIn=false;
var volumes=air.StorageVolumeInfo.StorageVolumeInfo.getStorageVolumes();
对于(变量i=0;i”);
}
}否则{
$(“#内容”).append(“此设备不可移动”

”; } } 函数onVolumeUnmount(e){ $('#content').html('再见!'); } 函数下载文件(远程文件、存储){ 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,函数(e){ var myByteArray=new air.ByteArray(); myURLStream.readBytes(myByteArray,0,myURLStream.bytesAvailable); var myFileStream=new air.FileStream(); openAsync(myFile,air.FileMode.WRITE); myFileStream.writeBytes(myByteArray,0); myFileStream.close(); }); 加载(new air.URLRequest(remoteFile)); }
看起来我可以简单地提供nativePath。说明:如果在引用文件时使用文本本机路径,则它只能在一个平台上工作。例如,以下文件对象只能在Windows上工作:new air.File(“C:\Documents and Settings\joe\My Documents\test.txt”)
var myFile = new air.File("file:///" + storage).resolvePath(fn);