forked from ismael-jimoh/Media-FilePath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexDownload2.html
56 lines (51 loc) · 1.94 KB
/
indexDownload2.html
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
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE HTML>
<html>
<head>
<meta name = "viewport" content = "user-scalable=no,width=device-width" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Test Page</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<style type="text/css">
* {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
</style>
<script type="text/javascript" charset="utf-8">
function init(){
document.addEventListener("deviceready", ready, true);
}
function ready() {
console.log("Thunderbirds are go!");
}
function dLoad() {
console.log("In Download Function");
var remoteFile = "http://i3.kym-cdn.com/entries/icons/original/000/000/080/doubt.jpg";
var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1);
console.log(remoteFile +" "+ localFileName);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile(localFileName, {create: true, exclusive: false}, function(fileEntry) {
var localPath = fileEntry.toURL();
console.log(localPath);
var ft = new FileTransfer();
ft.download(remoteFile,
localPath, function(entry) {
console.log("ft.download finally here");
var dwnldImg = document.getElementById("dwnldImg");
dwnldImg.src = entry.toURL();
dwnldImg.style.visibility = "visible";
dwnldImg.style.display = "block";
}, fail);
}, fail);
}, fail);
}
function fail(error) {
console.log(error.code);
}
</script>
</head>
<body onload="init();">
<br><br>
<a href="#" onclick="dLoad()">Download and display image</a>
<img src="" id="dwnldImg" style="display: none"/>
</body>
</html>