【问题标题】:error to filetransfer.download in android (erro code 1)android 中的 filetransfer.download 出错(错误代码 1)
【发布时间】:2014-05-02 15:38:02
【问题描述】:
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

我有,项目中的cordova.js,有cordova.js的链接,但如果有人帮忙,有这个错误,真的很感激。

【问题讨论】:

    标签: android cordova phonegap-plugins


    【解决方案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);
    

    【讨论】:

    • 一个问题,dummy.txt 是针对文件的 *.txt 我们是针对所有文件的吗?
    • 不仅.txt文件所有文件yaar(pdf...)...成功了啊?
    • 我有最新版本的科尔多瓦,而你呢?
    • 我在大学阶段需要这个,想法是有一个在线文件并在发生更改时更新网站,替换文件后我已经全部丢失了:/
    • @Fabio 检查这个pastie.org/9142177 无需更改任何内容,只需复制和粘贴并让我知道结果。在 2.9 和 3.3 版本中测试。
    猜你喜欢
    • 1970-01-01
    • 2015-01-19
    • 1970-01-01
    • 1970-01-01
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    相关资源
    最近更新 更多