尽管在文档或此论坛中找到了许多示例,但我找不到使用 Cordova 下载文件的方法...
首先,我得到了 rootFS:
function gotFS(fileSystem) {
console.log("got filesystem");
// save the file system for later access
console.log(fileSystem.root.fullPath);
// displays "/" on desktop
// displays "file:///mnt/sdcard" on android with SD Card
window.rootFS = fileSystem.root;
}
document.addEventListener('deviceready', function() {
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, function(){
console.log("error getting LocalFileSystem");
});
}, false);
上传脚本:
// Creating the image directory
imageDir = rootFS.getDirectory("imagesContent", {create: true},
function(){
// Success
},
function(error){
console.log("ERROR getDirectory");
console.log(error);
}
);
// Creating and Downloading the image
imgFile = imageDir.getFile(filename, {create: true, exclusive: true},
function (){
var localPath = rootFS.fullPath+'/imagesContent/'+filename;
fileTransfer = new FileTransfer();
fileTransfer.download('http://example.com/images/'+filename,
localPath,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function (error) {
console.log(error);
console.log('download error: ' + error.code);
console.log("download error source " + error.source);
console.log("download error target " + error.target);
}
);
},
function (error){
console.log("ERROR getFile");
console.log(error);
}
);
我在控制台中收到此错误:未捕获的类型错误:
Cannot call method 'getFile' of undefined
uri 在 config.xml 中被授权。