2

私のアプリケーションでは、画像配列をサーバーに追加したい

public void executeMultipartRequest(String eqname, String eqdesc,String CatId,String eqserial){
try{
     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= "http://njjjjjbjjb.com/bbbbbbbb/interface/m.php?method=add";

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

     postRequest.setEntity(reqEntity);
     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){
    e.printStackTrace();


}



 }

上記のコードを使用すると、単一の Image をアップロードできますが、Image Array をアップロードしたいので、Image Array をアップロードする方法を教えてください。

4

1 に答える 1

6

これで試してください:

reqEntity.addPart("eqphoto[0]", bab0);
reqEntity.addPart("eqphoto[1]", bab1);
reqEntity.addPart("eqphoto[2]", bab2);
于 2013-01-25T20:04:25.513 に答える