Skip to content

Instantly share code, notes, and snippets.

@devluis
Forked from deyvin/upload.js
Created April 9, 2014 01:04
Show Gist options
  • Save devluis/10215592 to your computer and use it in GitHub Desktop.
Save devluis/10215592 to your computer and use it in GitHub Desktop.
var win = Titanium.UI.currentWindow;
var ind=Titanium.UI.createProgressBar({
width:200,
height:50,
min:0,
max:1,
value:0,
style:Titanium.UI.iPhone.ProgressBarStyle.PLAIN,
top:10,
message:'Uploading Image',
font:{fontSize:12, fontWeight:'bold'},
color:'#888'
});
win.add(ind);
ind.show();
Titanium.Media.openPhotoGallery({
success:function(event)
{
Ti.API.info("success! event: " + JSON.stringify(event));
var image = event.media;
var xhr = Titanium.Network.createHTTPClient();
xhr.onerror = function(e)
{
Ti.API.info('IN ERROR ' + e.error);
};
xhr.onload = function()
{
Ti.API.info('IN ONLOAD ' + this.status + ' readyState ' + this.readyState);
};
xhr.onsendstream = function(e)
{
ind.value = e.progress ;
Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress+' '+this.status+' '+this.readyState);
};
// open the client
xhr.open('POST','http://www.myserver.com/route/to/action');
xhr.setRequestHeader("Connection", "close");
// send the data
xhr.send({media:image});
},
cancel:function()
{
},
error:function(error)
{
},
allowImageEditing:true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment