gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:40:57 26 4
gpt4 key购买 nike

我正在为 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com