I need to upload multiple images to PHP server from Android application. Multiple means that user can upload just 1 picture, or 2, or 3 or even 5 images.
Images I need to send to server with parameter path[numberOfImage], like this:
reqEntity.addPart("path[0]", bab); With this code I can upload an image to server.
File file1 = new File(selectedPath1); Bitmap bitmap = decodeFile(file1); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, 75, bos); byte[] data = bos.toByteArray(); try { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(urlString); ByteArrayBody bab = new ByteArrayBody(data, "test.jpg"); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("path[0]", bab); post.setEntity(reqEntity); HttpResponse response = client.execute(post); resEntity = response.getEntity(); response_str = EntityUtils.toString(resEntity); }
Arrayfor instance), and make as muchHTTP POSTrequests as files you have.