Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Download remote files async with Titanium
<body style="background-color:#1c1c1c;margin:0">
<div style="border-top:1px solid #404040">
<div style="color:#fff;;padding:10px">Welcome to Titanium</div>
<script type="text/javascript">
localFile = Titanium.Filesystem.getDesktopDirectory().toString() +
Titanium.Filesystem.getSeparator() +
remoteFile = '';
var httpClient = Titanium.Network.createHTTPClient();
// Data received
httpClient.onload = function(e) {
// Create a filestream and write the received data to a file
var writeFile = Titanium.Filesystem.getFile(localFile);
var writeStream = Titanium.Filesystem.getFileStream(writeFile);;
// Handle state change
httpClient.onreadystatechange = function(e) {
if (e.readyState == 4) {
// Download finished
// Handle error event
httpClient.onerror = function(e) {
console.log('HTTP error!');
};'GET', remoteFile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.