I have an android app which let the user to submit a form , now this form can have 9 bitmaps (MAX). now my code run well , but it takes too long to upload the images . is there a better way to upload images ??
my code :
Iterator<String> it = car_images.iterator();
int i = 0;
while (it.hasNext()) {
String imagepath = it.next();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Bitmap b = BitmapFactory.decodeFile(imagepath);
b.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
entity.addPart("image_" + i, new ByteArrayBody(data,
"myImage.jpg"));
Log.d("image loaded", "image_" + i);
++i;
}
put.setEntity(entity);
HttpResponse repsone = client.execute(put);
You can run the upload tasks in parallel using Threads, which could speedup the upload. Android developer’s guide has good documentation (with sample code) available on Threads and process.