Created
March 16, 2015 14:08
-
-
Save nitrag/8e8bad09d1ccf2880822 to your computer and use it in GitHub Desktop.
Titanium file download function (not working large files)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function download(localFile, remoteFile, name){ | |
var progressBar = Titanium.UI.createProgressBar({ | |
width: "80%", //describes the width | |
height:50, //describes the height | |
bottom: "25%", | |
min:0, //Minimum position | |
max:1, //Maximum value for the progress | |
value:0, | |
color: '#fff', | |
message: 'Downloading ' + name + '...', | |
font:{fontSize:12, fontWeight:'bold'} | |
}); | |
$.configMap.add(progressBar); | |
progressBar.show(); | |
var myHttpClient = Ti.Network.createHTTPClient(); | |
myHttpClient.timeout = 60000; | |
myHttpClient.onload = function(e){ | |
var fileSavingPath = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, localFile; | |
fileSavingPath.write(e.responseData); | |
fileSavingPath = null; | |
$.configMap.remove(progressBar); | |
progressBar = null; | |
alert('Download complete'); | |
}; | |
myHttpClient.ondatastream = function(e) { | |
progressBar.value = e.progress; | |
}; | |
myHttpClient.open("GET", remoteFile); | |
myHttpClient.send(null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment