Uploading a LOT of pictures in the background

COBRASoft

Active Member
Licensed User
Longtime User
Hi all,

My app needs to have continuous online connection for communication with a database. I use HttpUtils for this and POST messages. This works perfectly so far.

Next to this, my app needs to 'upload' hundreds of pictures in a background thread with some additional information (again using POST messages).
Can somebody please explain me how I can do this the best so my app remains responsive at the same time? The pictures will be stored as JSon text in Base64 string together with the other fields for the POST message on the SD card.

Greetings,
Sigurd
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Sending Http requests is done in the background. This means that your program should be responsive during the communication.

Converting large images to base64 can be a heavy operation. As I wrote before, if you can try to avoid it. It will make everything much lighter and faster.
If you cannot avoid it you should try doing the conversion in the background with the Threading library.
 
Upvote 0

COBRASoft

Active Member
Licensed User
Longtime User
Hi Erel,

I would like to find a better way to upload those pictures than Base64, but since Map doesn't support byte(), I have not much choice. I need to POST in JSon so JSonGenerator, based on a map... Unless you can alter this behaviour of a map so that byte() is supported :).

My pictures are all 640x480, quality 75. This means about 50 to 90KB per picture. The conversion to Base 64 goes quite fast on my device. Thanks for the advice on threading, although I was thinking about writing a service for this since I can't POST multiple messages without changing HtppUtils.

Greetings,
Sigurd
 
Upvote 0

COBRASoft

Active Member
Licensed User
Longtime User
Hi Erel,

I've tested to put an array of bytes in a map, it doesn't work. I guess it's because the reference is put in the map instead of the value. The JSonGenerator doesn't work with that reference.

I convert the image to a string (Base64), if you have another (better) way to convert the picture to a string, please tell me :).

Greetings,
Sigurd
 
Upvote 0

COBRASoft

Active Member
Licensed User
Longtime User
Erel, how to use HttpUtils from a service? the 'Main' activity will never be visible (and may not be visible). I need a service that runs itself every few minutes using StartServiceAt (works already). The problem is the ActivityCallBack from the HtppUtils... I don't have a visible Activity and everything should stay in my service... Any idea?
 
Upvote 0

jimmyjace

Member
Licensed User
Longtime User
Posting images inside xml

Hi Erel,

I have an application where the user takes photos and sends them to the server. How is the best way to post the image inside an XML wrapper to post to a web service?

I've been converting the image bytes to base64, but the android application crashes.

Any help would be very much appreciated.

Kind Regards,

Jason
 
Upvote 0
Top