将多个图像与android中的标记一起发送到服务器

时间:2016-06-14 07:50:05

标签: php android

我可以使用this link在服务器上发送多个图像,但我还需要发送包含这些多个图像的标记。你能否在我的php脚本和我链接的java代码中建议我需要做哪些更改?

2 个答案:

答案 0 :(得分:1)

添加此库。

     compile 'org.apache.httpcomponents:httpmime:4.3.6'
     compile 'org.apache.httpcomponents:httpcore:4.3.3'

而不是

  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();
}

}

您可以发送多个图像文件并将其添加到entity.addPart(" files",                 new FileBody(sourceFile)); 和使用StringBody的多个标签

希望它有所帮助!!

答案 1 :(得分:0)

我只需要做multipart.addFormField(“tag”,“Your String”);