I am able to send multiple images on the server by using this link, but I also need to send a tag with those multiple images. Can you suggest what changes I need to do in my php script and my java code that are in that link?
Asked
Active
Viewed 324 times
1
-
tag is basically a string – Kunal Saini Jun 14 '16 at 07:50
-
you can use a multipart request, try using retrofit library, remember that large data transfer is not recommend with multipart. – Sarthak Mittal Jun 14 '16 at 07:56
-
@SarthakMittal its just a small string but i need to send it with the images array – Kunal Saini Jun 14 '16 at 07:58
-
i m talking about image data – Sarthak Mittal Jun 14 '16 at 09:13
2 Answers
1
Add this library.
compile 'org.apache.httpcomponents:httpmime:4.3.6'
compile 'org.apache.httpcomponents:httpcore:4.3.3'
And than
private void sendImage(final String fileString, String fileMessageId)
{
Bitmap bitmap;
DataOutputStream dos = null;
String sResponse = null;
bitmap = BitmapFactory.decodeFile(fileString);
File sourceFile = new File(fileString);
String upLoadServerUri = WSConfig.UPLOAD_FILE_URL;
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(upLoadServerUri);
try {
MultipartEntity entity = new MultipartEntity();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
entity.addPart("files",
new FileBody(sourceFile));
entity.addPart("tag",
new StringBody("any tag here"));
httpPost.setEntity(entity);
HttpResponse response;
try {
response = httpClient.execute(httpPost);
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
sResponse = reader.readLine();
} catch (IOException e1) {
e1.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
You can send multiple image file and add it in entity.addPart("files", new FileBody(sourceFile)); and multiple tags too using StringBody
Hope it helps !!

Tanveer Bulsari
- 213
- 1
- 10
-
Thank you very much though it was not the answer that i expected but your one line entity.addPart("tag",new StringBody("any tag here")); gave me a great hint and i was able to complete my task – Kunal Saini Jun 14 '16 at 10:29
-
Sorry but this was not the answer as i said above as according to my question i want the change in the code at that link – Kunal Saini Jun 14 '16 at 10:32