以前的版本用entry.fullPath,是可行,
但更新新版3.5之后就不行要用FileEntry.toURL()
and DirectoryEntry.toURL()
贴上别人的例子
window.appRootDirName
= "download_photo";
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("device is ready");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function fail() {
console.log("failed to get filesystem");
}
function gotFS(fileSystem) {
console.log("filesystem got");
window.fileSystem = fileSystem;
fileSystem.root.getDirectory(window.appRootDirName, {
create : true,
exclusive : false
}, dirReady, fail);
}
function dirReady(entry) {
window.appRootDir = entry;
console.log("application dir is ready");
}
function downloadFile(fileurl){
var uri = encodeURI(fileurl);//定义下载的路径
//var
filePath =
window.appRootDir.fullPath
+uri.substr(uri.lastIndexOf('/')
+ 1);主要这里以前是这样子
var filePath = window.appRootDir.toURL()
+uri.substr(uri.lastIndexOf('/')
+ 1);
alert("start");
var fileTransfer = new FileTransfer();
alert(window.appRootDir.fullPath);
fileTransfer.download(
uri,
filePath,
function(entry) {
alert("success");
alert(entry.fullPath);
//此处调用打开文件方法
//OpenFile(entry.fullPath);
//window.location.href = window.appRootDir.fullPath;
console.log("download complete: " + entry.fullPath);
},
function(error) {
alert("error");
alert(JSON.stringify(error));
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
}
)}