Skip to content

Instantly share code, notes, and snippets.

@Astrovic
Last active July 23, 2019 10:52
Show Gist options
  • Save Astrovic/f1e1169aedd6f441089f8dc06ed0d7f9 to your computer and use it in GitHub Desktop.
Save Astrovic/f1e1169aedd6f441089f8dc06ed0d7f9 to your computer and use it in GitHub Desktop.
Titanium upload test
var win = Ti.UI.createWindow();
var progress = Ti.UI.createProgressBar({
width:200,
min:0,
max:1,
value:0,
tintColor : "red"
});
win.add(progress);
var timestamp = Date.now();
var b = win.toImage();
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory+"test");
file.write(b)
win.addEventListener('open', function() {
var xhr = Ti.Network.createHTTPClient({
onload: function() {
var time_passed = Math.floor((Date.now()-timestamp)/1000);
Ti.API.info(time_passed + ' SUCCESS');
win.close()
},
onsendstream: function(e) {
var time_passed = Math.floor((Date.now()-timestamp)/1000);
Ti.API.info(time_passed + ' PROGRESS ' + e.progress);
progress.setValue(e.progress);
}
});
xhr.open('POST', 'https://httpbin.org/post');
xhr.send({data: file})
});
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment