javascript - Cordova 的 FileTransfer 写入错误(代码 1)

标签 javascript android cordova file-transfer cordova-plugins

我正在为 Android 使用 Cordova 4.2.0。

我有一些麻烦 FileTransfer plugin好好工作。估计是写错了

exception:".myApp\/contentImages\/20150110220101.jpg: open failed: ENOENT (No such file or directory)"

filename 之前已经过测试,目前还不存在:

rootFS.getFile('.myApp/contentImages/'+file,{create:false},
    function(){
        console.log(file+' already exists');
    },
    function(error){
        console.log(file+" does not exist locally");
        console.log("Error #"+error.code);
        download(file);
    }
);

这里是下载函数:

function download (filename){
    var localPath = rootFS.fullPath+'/.myApp/contentImages/'+filename;
    var fileTransfer = new FileTransfer();
    fileTransfer.download(
        encodeURI('http://distantApp/contentImages/'+filename), // This file exists
        localPath,
        function(entry) {
            console.log("download complete: " + entry.fullPath);
        },
        function (error) {
            console.log('download error: ' + error.code + ": "+error.exception+" ; source " + error.source+" ; target " + error.target);
        }
    );
}

可能是什么问题?

编辑 rootFS

的代码
function onDeviceReady(){
    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, function(){
        console.log("error requesting LocalFileSystem");
    });
}
function gotFS(fileSystem) {
    console.log("got filesystem: "+fileSystem.name); // displays "persistent"
    console.log(fileSystem.root.fullPath); // displays "/"
    window.rootFS = fileSystem.root;
}

最佳答案

问题是由于 Cordova 从以前的版本升级引起的。

未正确识别本地文件的路径:.fullPath现已过时,应由 .toURL() 替换。

关于javascript - Cordova 的 FileTransfer 写入错误(代码 1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28129044/

相关文章:

javascript - 将数据复制到 v8::ArrayBuffer

android - 在 ImageView 中显示 gif 和 Movie

android - 如何显示实时运行的时间?

java - SharedPreferences 无法工作/保存 EditText 字段中的数据

javascript - 使用 navigator.camera 或纯 javascript 拍摄照片

android - 自定义 cordova 插件中的 package.json 无效

javascript - 如何将一个事件监听器附加到多个对象?

javascript - 使用jQuery根据背景颜色查找div

javascript - 多个 Onclick 图像

node.js - Node Js,带有 EJS 的 Express Js 到 Android 在 PhoneGap 中不起作用?