error to filetransfer.download in android (erro code 1)

走远了吗. 提交于 2019-12-01 12:13:30

问题


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. dowload error source https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/t1.0-1/c14.4.48.48/150734_264955536974736_682293823_t.jpg
  2. download error target//teste_recev/image_name.jpg
  3. upload error code1

i have, the cordova.js in project, have link for cordova.js but have this erros if someone to help, really appreciate it.


回答1:


Try like this

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);


来源:https://stackoverflow.com/questions/23431890/error-to-filetransfer-download-in-android-erro-code-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!