Last active
July 23, 2019 10:52
-
-
Save Astrovic/f1e1169aedd6f441089f8dc06ed0d7f9 to your computer and use it in GitHub Desktop.
Titanium upload test
This file contains 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
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