Showing a progress silder and percentage when uploading data

121 views
Skip to first unread message

cubiq1

unread,
Aug 26, 2014, 1:18:04 PM8/26/14
to codenameone...@googlegroups.com
Hi,

My app uploads images to a server. I'd like to display the actual progress of the upload in a dialog. What would be the best way to achieve this?

I've tried this but I don't seem to be getting the correct values:

       NetworkManager.getInstance().addProgressListener(new ActionListener() {

       
public void actionPerformed(ActionEvent evt) {

           
NetworkEvent e = (NetworkEvent)evt;
           
System.out.println(e.getProgressPercentage());
       
}});
           
       
NetworkManager.getInstance().addToQueueAndWait(r);

Many thanks

Shai Almog

unread,
Aug 27, 2014, 12:09:55 AM8/27/14
to codenameone...@googlegroups.com
Hi,
you need to check the event type. You can use the SliderBridge which does that internally or just reference its source.

cubiq1

unread,
Aug 27, 2014, 10:01:24 AM8/27/14
to codenameone...@googlegroups.com
Hi, thanks.

I've tried the following but it's still not working (the Slider component just bounces back-and-forth, there's no actual percentage progress shown).

       // Method 1
       
SliderBridge.bindProgress(r, findSlider());
       
NetworkManager.getInstance().addToQueueAndWait(r);
          
       // Method 2

       
NetworkManager.getInstance().addProgressListener(new ActionListener() {
               
           
public void actionPerformed(ActionEvent evt) {

               
               
if (evt instanceof NetworkEvent) {
                   
                   
NetworkEvent e = (NetworkEvent)evt;
                   
System.out.println("Progress: " + e.getProgressPercentage());
               
}
       
}});

Any other ideas?

Shai Almog

unread,
Aug 27, 2014, 1:00:55 PM8/27/14
to codenameone...@googlegroups.com
That happens when we don't get actual progress and spend most of our time in a pending to connection mode.

cubiq1

unread,
Aug 28, 2014, 9:48:50 AM8/28/14
to codenameone...@googlegroups.com
Hi,

Is there anyway to show the actual upload progress?

My app uploads images to a server (as base64 strings) via buildRequestBody(OutputStream os) so I'd assume most of the time isn't spent in a pending to connection mode.

Thanks

Shai Almog

unread,
Aug 29, 2014, 1:11:14 AM8/29/14
to codenameone...@googlegroups.com
Hi,
it should work although I haven't tested this in a while. I suggest debugging this and seeing what happens.

cubiq1

unread,
Aug 29, 2014, 4:45:58 AM8/29/14
to codenameone...@googlegroups.com
Hi,

I spent a couple hours this morning debugging and made a very simple app to test things.

Basically, it has one button which downloads an image from a URL while showing a progress dialog. And another button which uploads an image to my webserver (as a base64 encoded string).

The download operation displays the progress correctly whereas the upload operation doesn't, and just shows the slider bouncing back-and-forth.

Is this likely due to the way my webserver is configured? Or should it work seamlessly?

Thanks

Shai Almog

unread,
Aug 29, 2014, 10:18:30 AM8/29/14
to codenameone...@googlegroups.com
Hi,
its possible that upload isn't supported for the progress indication since this feature has predated the MultipartRequest function by quite some time.

cubiq1

unread,
Aug 29, 2014, 10:28:36 AM8/29/14
to codenameone...@googlegroups.com
Hi,

I'm actually using a regular ConnectionRequest, not a MultipartRequest, and sending the image data via the body of the request as a base64 string. For example:

    @Override
   
protected void buildRequestBody(OutputStream os) throws IOException {

        os
.write(data.getBytes("UTF-8"));
   
}

I can only assume SliderBridge doesn't update the percent complete value when uploading data?

Thanks

Shai Almog

unread,
Aug 30, 2014, 12:33:51 AM8/30/14
to codenameone...@googlegroups.com
Hi,
while that probably won't work for you in the real world its inherently the same. That means we built the functionality before we had any significant upload code to debug.

cubiq1

unread,
Aug 30, 2014, 7:29:34 AM8/30/14
to codenameone...@googlegroups.com
Hi, the data is sent to the server in JSON format and seems to be working fine.

Is the best I can do, in this case, show the user an InfiniteProgress dialog?

Thanks

Shai Almog

unread,
Aug 30, 2014, 1:15:02 PM8/30/14
to codenameone...@googlegroups.com
Hi,
the best you can do is debug the code and let us know what is happening specifically.
Reply all
Reply to author
Forward
0 new messages