var app = {
// Application Constructor
initialize: function () {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
// deviceready Event Handler
onDeviceReady: function () {
this.receivedEvent();
},
// get DOM
('download');
dlDom.onclick = function () {
_this.dl();
}
},
dl: function () {
var that = this;
console.log(requestFileSystem)
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 5 * 1024 * 1024, function (fs) {
//创建文件
console.log(111)
var url = 'http://k.zol-img.com.cn/sjbbs/7692/a7691515_s.jpg';
fs.root.getFile('download.jpg', {create: true, exclusive: false}, function (fileEntry) {
alert(fileEntry.nativeURL)
alert(fileEntry.toURL())
download(fileEntry, url);
}, function () {
alert('shibai')
});
}, function () {
alert('shibai')
})
// var ft = new FileTransfer();
function download(fileEntry, url) {
var ft = new FileTransfer();
var fileURL = fileEntry.toURL();
// var fileURL = 'storage';
//监听下载进度
ft.onprogress = function (e) {
console.info(e);
if (e.lengthComputable) {
console.log('当前进度:' + e.loaded / e.total);
}
}
ft.download(url, fileURL, function (entry) {
alert('下载成功');
console.info(entry);
console.log('文件位置:' + entry.toURL());
that.url = entry.toURL()
that.$$('myImage').src= entry.toURL()
}, function (err) {
alert("下载失败!");
}, null, // or, pass false
{
//headers: {
// "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
//}
});
}
},
};
app.initialize();
网友评论