android中的filetransfer.download错误(错误代码1)

时间:2014-05-02 15:38:02

标签: android cordova phonegap-plugins

document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
//request the persistent file system
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fileSystemSuccess, fileSystemFail);
}

function fileSystemSuccess(fileSystem) {
    var directoryEntry = fileSystem.root; // to get root path to directory
    directoryEntry.getDirectory("teste_recev", {create: true, exclusive: false}, onDirectorySuccess, onDirectoryFail);
    var rootdir = fileSystem.root;
    var fp = rootdir.fullPath;
    fp = fp+"/teste_recev/image_name.jpg";
    var fileTransfer = new FileTransfer();
   fileTransfer.download("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/t1.0-1/c14.4.48.48/150734_264955536974736_682293823_t.jpg",fp,  
        function(entry) {
            alert("download complete: " + entry.fullPath);
        },
        function(error) {
            alert("download error source " + error.source);
            alert("download error target " + error.target);
            alert("upload error code" + error.code);
        }
    );
}
function onDirectorySuccess(parent) {
    console.log(parent);
}

function onDirectoryFail(error) {
    alert("Unable to create new directory: " + error.code);
}

function fileSystemFail(evt) {
    console.log(evt.target.error.code);

}

But have a error:
  1. 下载错误来源https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/t1.0-1/c14.4.48.48/150734_264955536974736_682293823_t.jpg
  2. 下载错误目标// teste_recev / image_name.jpg
  3. 上传错误代码1
  4. 我有,项目中的cordova.js有cordova.js的链接,但如果有人帮忙的话,有这个错误,非常感谢。

1 个答案:

答案 0 :(得分:1)

试试这个

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function gotFS(fileSystem) {
           fileSystem.root.getDirectory("your dir", {create: true}, function fileSystemSuccess(fileSystem){
                fileSystem.getFile("dummy.txt",{create: true,exclusive:false},function gotFileEntry(fileEntry){
                    var path = fileEntry.fullPath.replace("dummy.txt","");
                    fileEntry.remove();
                    var fileTransfer = new FileTransfer();
                    fileTransfer.download(FILE_DOWNLOAD_URL, path+""+your -savedName,function(theFile){
                        alert("File Downloaded Successfully " + theFile.toURI());
                    },function(error){
                        alert("File Transfer failed" + error.message);
                    });
                },fail);
            });
    }, fail);