科尔多瓦的文件传输写入错误(code 1) [英] Cordova's FileTransfer Writing Error (Code 1)
本文介绍了科尔多瓦的文件传输写入错误(code 1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是科尔多瓦4.2.0为Android。
我有一些麻烦让的文件传输的插件的正常工作。我想有一个写入错误
例外:对myApp \ / contentImages \ /20150110220101.jpg:打开失败:ENOENT(没有这样的文件或目录)。
文件名的是previously测试,并不存在:
'。对myApp / contentImages /' rootFS.getFile(+文件,{创建:假},
功能(){
的console.log(文件+'已经存在);
},
功能(错误){
的console.log(文件+于本地存在);
的console.log(错误#+错误code);
下载文件);
}
);
这里是下载功能:
功能下载(文件名){
VAR了localPath = rootFS.fullPath +'/对myApp / contentImages /。'+文件名;
VAR文件传输=新的文件传输();
fileTransfer.download(
EN codeURI('HTTP:// distantApp / contentImages /+文件名),//这个文件存在
localPath来,
功能(输入){
的console.log(下载完成:+ entry.fullPath);
},
功能(错误){
的console.log(下载错误:'+错误code +:+ error.exception +源+ error.source +目标+ error.target);
}
);
}
这可能是什么问题?
修改的
$ C $下 ROOTFS
函数onDeviceReady(){
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT,0,gotFS,函数(){
的console.log(错误请求LocalFileSystem);
});
}
功能gotFS(文件系统){
的console.log(得到的文件系统:+ fileSystem.name); //显示老大难
执行console.log(fileSystem.root.fullPath); //显示/
window.rootFS = fileSystem.root;
}
解决方案
该问题是由科尔多瓦从previous版本升级造成的。
本地文件的路径没有被正确识别: .fullPath
现在已经过时,应由 .toURL()$ C所取代$ C>。
I'm using Cordova 4.2.0 for Android.
I have some troubles to get FileTransfer plugin work properly. I suppose that there is a writing error
exception:".myApp\/contentImages\/20150110220101.jpg: open failed: ENOENT (No such file or directory)"
filename was previously tested and does not exist yet:
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);
}
);
And here is the download function:
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);
}
);
}
What could be the problem?
EDIT
Code for 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;
}
解决方案
The problem was caused by an upgrade of Cordova from a previous version.
The path of local files was not properly identified: .fullPath
is now obsolete and should be replaced by .toURL()
.
这篇关于科尔多瓦的文件传输写入错误(code 1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文