Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
technolgia
Posts: 96
Registered: ‎06-11-2009
My Device: Not Specified
Accepted Solution

Uploading images to the server

Hello All,

 

My requirement is that the user captures images and the images needs to be uploaded to the server in the background while the user can continue to perform other tasks with the application. I would like to know what is the best way to implement a background thread which uploads images to the server.Could someone kindly provide me with some inputs. Thanks in advance.

 

Regards,

S.A.Norton Stanley

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Uploading images to the server

There is no problem with the Background Thread.  I would recommend that you have just one Thread, which picks up the first element of a persisted list of the images to be sent.  Once the image it has been sent, the Thread deletes the entry for the one just sent, and picks up the next one.  You need proper synchronization round the updating of the list, I typically use Vector which is in theory synchronized properly but I do a check anyway. 

 

The Thread processing has a public add method which will start the Thread if it is not currently running.  The Thread stops when there is nothing in the queue. 

 

All this is pretty standard I think.  But there a few things that I think you may need to add to this processing to make it more robust:

 

a) You may give the user the option to delete the image once it is sent.  Remember in fact that the user could delete the image before it is sent and so the processing must take care of that.

 

b) I would recommend a Server component to this that receives the Images.  You can then pass the image in chunks because some communication methods have limits on the size of data that can be transferred in one connection.  I would recommend breaking the image up into 64 KB chunks.  You should include a restart mechanism in here too, so that you can resend just the unsent parts of an image after a failure. 

 

c) You need to think about whether the server and the intervening gateways will process binary data, or do you have to encode it into text (Base 64 seems like the way to go if you do).

 

d) You may consider allowing the user to restrict communication to specific connections, like WiFi and/or 3G. 

 

e) You will need to be very careful about coding restart and recovery, so that the processing does not die unexpectedly.

 

Hope this is useful.  . 

Developer
technolgia
Posts: 96
Registered: ‎06-11-2009
My Device: Not Specified

Re: Uploading images to the server

Hello Peter,

 

Thank you for your quick response. This was really really helpful. I use the Base 64 route to send the images to the server. I noticed that when the picture size is set to 2048 x 1536, the image does not get uploaded to the server and remains in the queue, however with the picture  size 1024 x 768 or 480 x 360 the image gets uploaded within no time to the server. I use HttpConnection inorder to transmit the image. Should i be reducing the size of the image when the size is set to 2048 x 1536? Am i missing out on something here? Kindly advice.

 

 

Thanking you,

Regards,

S.A.Norton Stanley

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Uploading images to the server

You need to track the error that is stopping your larger images being sent to know what to do to rectify the problem.  However one concern is the size of the image.  In terms of raw pixels, the 2048 x 1536 image size is 4 times as many pixels as the1024 x 768 and it could be that you have exceeded some size limit. 

 

As to whether you should scale or not, that depends on your requirement.  Certainly I would recommend that you scale on device if you can to reduce the data being sent.  Scaling is not that difficult, though the best approach depends on what level of OS you are targeting. 

Developer
technolgia
Posts: 96
Registered: ‎06-11-2009
My Device: Not Specified

Re: Uploading images to the server

Hello Peter,

 

Thank you. We are targetting OS 5.0 onwards. What is the best approcah on scaling?

 

Thanking you,

Regards,

S.A.Norton Stanley

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Uploading images to the server

Bitmap.scaleInto(...)

 

There are issues if you have transparent images, in which case look at this:

http://supportforums.blackberry.com/t5/Java-Development/Resizing-Transparent-Bitmaps/ta-p/703239

Developer
technolgia
Posts: 96
Registered: ‎06-11-2009
My Device: Not Specified

Re: Uploading images to the server

Hello Peter,

 

Thanks a ton.

 

Regards,

S.A.Norton Stanley