我试图让Cordova文件插件和Cordova文件传输工作,我的代码(下面)应该创建一个新文件夹' Makes'并将图像下载到该新文件夹中,但它只是抛出错误代码1,但我无法弄清楚原因,有人可以指出我正确的方向:
function onAppReady(){
if(navigator.splashscreen && navigator.splashscreen.hide){
navigator.splashscreen.hide();
}
updateImages();
}
function updateImages(){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fileSystemSuccess, fileSystemFail);
function fileSystemSuccess(fileSystem){
var directoryEntry=fileSystem.root;
directoryEntry.getDirectory("Makes", {create:true, exclusive:false}, onDirectorySuccess, onDirectoryFail);
}
function onDirectorySuccess(parent){
var rootdir = fileSystem.root;
var fp = parent.toURL();
var download_link=encodeURI('https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/1122px-Wikipedia-logo-v2.svg.png');
var fpFull=fp+'Makes/Wikipedia.png';
filetransfer(download_link, fpFull);
}
function onDirectoryFail(error){alert("Unable to create new directory: "+error.code);}
function fileSystemFail(evt){alert(evt.target.error.code);}
}
function filetransfer(download_link, fp){
var fileTransfer=new FileTransfer();
fileTransfer.download(download_link, fp, function(entry){
console.log("download complete: "+entry.fullPath);
},
function(error){
console.log("download error: "+error.code+' - '+error.source+' - '+error.target);
});
}
document.addEventListener("app.Ready", onAppReady, false);