Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nitrag
Created March 16, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitrag/8e8bad09d1ccf2880822 to your computer and use it in GitHub Desktop.
Save nitrag/8e8bad09d1ccf2880822 to your computer and use it in GitHub Desktop.
Titanium file download function (not working large files)
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