Created
March 5, 2011 17:29
-
-
Save codeboxed/856526 to your computer and use it in GitHub Desktop.
Download script using Titanium API
This file contains hidden or 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
<html> | |
<head></head> | |
<body style="background-color:#1c1c1c;margin:0"> | |
<div style="border-top:1px solid #404040"> | |
<div style="color:#fff;;padding:10px">Welcome to Titanium</div> | |
</div> | |
<script type="text/javascript"> | |
var url = 'http://www.codeboxed.com'; | |
// Initialize the HTTPClient object | |
var httpClient = Titanium.Network.createHTTPClient(); | |
// Connect to the url above | |
if (httpClient.open('GET', url)) { | |
// Create the temporary file | |
var file = Titanium.Filesystem.createTempFile(); | |
// Set the path to desktop directory in our case | |
var filePath = Titanium.Filesystem.getDesktopDirectory().toString()+ | |
Titanium.Filesystem.getSeparator()+ | |
'index.html'; | |
// Copy the temporary file to our path | |
file.copy(filePath); | |
// Handle the reveived data (Titanium.Filesystem.File can also be used as a handler) | |
httpClient.receive(function(data) { | |
var file = Titanium.Filesystem.getFile(window['filePath']); | |
// Open the file created before and write to it the received data | |
var fileStream = file.open(Titanium.Filesystem.MODE_APPEND); | |
fileStream.write(data); | |
fileStream.close(); | |
}); | |
} else { | |
Titanium.API.info('cannot open connection'); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment