I have an HTTPClient that sends a stringified object of images (each object element is an object consisting of a hash and a base64 encoded string of the image). Upon initiating the upload, how can I show a progress bar that shows the progress of each image and the progress of the total operation?
In other words, assuming a total number of images of 5, I want the progress to initially show "Uploading 1 of 5" with the bar itself showing the progress of the first image. The message then changes to "Uploading 2 of 5" and resets the bar to show the progress of the second image.
The total number of images is variable.
Inside the event handler function for initiating the upload, I have the following code:
var progressBar = Ti.UI.createProgressBar({ id: 'progressBar', value: 1, message: 'Uploading 1 of '+imageCount, // imageCount is a global variable keeping track of the number of images height: 'auto', width: Ti.UI.FILL, top: 0, style: Ti.UI.iPhone.ProgressBarStyle.PLAIN }); $.updateWin.add(progressBar); $.updateWin.titleControl = progressBar.id; progressBar.show(); var postUpdate = Ti.Network.createHTTPClient({ onload: function(e) { close(); alert('Update submitted successfully'); }, onsendstream: function(e) { Ti.API.info(e.progress); // Currently just to see what it outputs } }); postUpdate.open('POST', 'http://mydomain.com/submit_update'); postUpdate.send({ images: JSON.stringify(images) // Just assume this is the only thing being sent, but it isn't });
images
is constructed in this format:
{ 1392261534 = { // Timestamp key md5: Ti.Utils.md5HexDigest(e.media), file: Ti.Utils.base64encode(e.media).text // The values aren't actually being entered like this, just for illustration }, ... }So how can I step through the object and show the progress of each image in turn while keeping track of the progress of the whole object?
And how do I represent the progress on the progress bar? I imagine I need to take the e.progress property and apply that to the width of the progressBar, but I'm not really sure how that works. I'm also trying to get it to show in the window title in iOS 7 , but setting the titleControl property doesn't seem to work.