In KS, the large file example was very helpful.
largeFile.addEventListener('click', function() { ind.value = 0; c = Titanium.Network.createHTTPClient(); c.setTimeout(10000); c.onload = function(e) { Ti.API.info("ONLOAD = "+e); }; c.ondatastream = function(e) { ind.value = e.progress ; Ti.API.info('ONDATASTREAM1 - PROGRESS: ' + e.progress); }; c.onerror = function(e) { Ti.UI.createAlertDialog({title:'XHR', message:'Error: ' + e.error}).show(); }; c.open('GET',myurl); c.send(); });Unfortunately it doesn't show how to save it into a particular directory/filename. Using the clues from "Set Web View (url)" I modified the c.onload function as shown below:
c.onload = function(e) { // Finished downloading Ti.API.info("ONLOAD = "+e); var f = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory,'tempfile.mp3'); f.write(this.responseData); };When myurl is an mp3 file that is around 18MB, this results in a file in the root of my sdcard named "tihttp#####tmp" and a file called "tempfile.mp3" in my <com.appid> subdirectory. When myurl is >30MB (I'm sure the actual boundary is somewhere in between 18-30MB), I get an error "The application... has stopped unexpectedly. Please try again (force close)". It does result in a valid file in the root of my sdcard named "tihttp#####tmp" and an empty "tempfile.mp3" in my <com.appid> subdirectory. The error is a result of the f.write(responseData) statement since the responseData is so large.
A couple (or more) questions:
How can I properly download large files into a particular filename?
Why is "tihttp#####tmp" produced? How can I write this mp3 file so that the android music player can recognize metadata? Does android clean this up? I don't want to leave large temporary files on my sdcard taking up space.
Thanks everyone!