Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created August 27, 2011 02:27
Show Gist options
  • Select an option

  • Save aaronksaunders/1174868 to your computer and use it in GitHub Desktop.

Select an option

Save aaronksaunders/1174868 to your computer and use it in GitHub Desktop.
Appcelerator Titanium iPad FileDownload Example
/**
* htp://blog.clearlyinnovative.com
*
* more appcelerator examples
*/
var c = Titanium.Network.createHTTPClient();
c.setTimeout(10000);
c.onload = function() {
Ti.API.info('IN ONLOAD ');
var filename = 'test.pdf';
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);
var win = Titanium.UI.createWindow({});
var wv = Ti.UI.createWebView({
url : f.nativePath,
bottom : 0,
left : 0,
right : 0,
top : 0
});
win.add(wv);
win.open();
};
c.ondatastream = function(e) {
Ti.API.info('ONDATASTREAM1 - PROGRESS: ' + e.progress);
var kb = Math.round(e.progress * c.getResponseHeader('Content-Length') / 1024);
Ti.API.info('Downloaded ' + kb + ' KB');
Titanium.API.info("Content-Length: " + c.getResponseHeader('Content-Length'));
};
c.onerror = function(e) {
Ti.API.info('XHR Error ' + e.error);
};
// open the client
c.open('GET', 'http://www.appcelerator.com/assets/The_iPad_App_Wave.pdf');
c.file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'test.pdf');
// send the data
c.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment