1

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?

Community
  • 1
  • 1
Kunal Saini
  • 138
  • 10

2 Answers2

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
0

I just have to do multipart.addFormField("tag","Your String");

Kunal Saini
  • 138
  • 10