Ali Ali - 1 year ago 131
Android Question

How to add Image Array from android to Server

In my application i want to add image array to server

public void executeMultipartRequest(String eqname, String eqdesc,String CatId,String eqserial){
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");
String urlPath= "";

System.out.println("URL Path is "+urlPath);

HttpPost postRequest = new HttpPost(urlPath);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("userid", new StringBody(FalconGearApp.getInstance().getUserId()));
reqEntity.addPart("sid", new StringBody(FalconGearApp.getInstance().getSessionId()));
reqEntity.addPart("categoryid",new StringBody( CatId));
reqEntity.addPart("eqname",new StringBody( eqname));
reqEntity.addPart("eqdescription",new StringBody( eqdesc));
reqEntity.addPart("eqserial", new StringBody(eqserial));
reqEntity.addPart("eqphoto", bab);
reqEntity.addPart("eqphoto", bab);
reqEntity.addPart("eqphoto", bab);

HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {

s = s.append(sResponse);


System.out.println("Response is: " + s);

}catch(Exception e){



Using above code I am able to upload single Image , but I want to upload Image Array so please help how can I upload Image Array,

Answer Source

Try with this :

reqEntity.addPart("eqphoto[0]", bab0);
reqEntity.addPart("eqphoto[1]", bab1);
reqEntity.addPart("eqphoto[2]", bab2);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download