1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| 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://www.gongjuji.net/Content/Images/hostoperate1.png';
fs.root.getFile('test1.png', { 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) {
console.log('下载成功');
console.info(entry);
console.log('文件位置:' + entry.toURL());
that.url=entry.toURL()
}, function (err) {
console.log("下载失败!");
}, null, // or, pass false
{
//headers: {
// "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
//}
});
}
}, |