|
<script type="text/javascript">
window.appRootDirName = "download_test"; //定义文件下载后的存放目录
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 定义为全局变量
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(file_url){
alert("in downloadFile the url:"+ file_url);
var fileTransfer = new FileTransfer();
var uri = encodeURI(file_url);
var file_name = file_url.substring(file_url.lastIndexOf("/") + 1);
var filePath = window.appRootDir.fullPath + "/" + file_name;
//alert('filename:'+file_name+';filepath:'+filePath);
fileTransfer.download(
uri,
filePath,
function(entry) {
alert('1111:' + entry.fullPath);
},
function(error) {
alert('2222 eorr:' + error);
console.log("download error source " + error.source);
console.log("download error target " + error.target);
// console.log("upload error code" + error.code);
}
);
}
</script>
<html>
<body>
<p><a href="#">doc格式文件</a></p>
</body>
</html>
代码以前在phonegap2.9上都正常的。但是想升级phonegap3.4。发现问题。
file-transfer和[size=2.5em]file插件都安装了。
|
|