2016-04-29 65 views
1

我想在多部分實體中發送具有文件路徑的字符串[]我得到了link(我的代碼太大而無法發佈,所以我發佈了參考鏈接),其中@rohit mandiwal代碼適用於無串[],但現在我有串發送多張圖片單個圖像[]如何發送多部分實體中的字符串數組

該服務我的服務器端代碼是類似的東西

@RequestMapping(value = "/Images", method = RequestMethod.POST) 
@ResponseBody 
@ResponseStatus(value = HttpStatus.OK) 
public ImageFilePath uploadFileImage(
     @RequestParam("file") MultipartFile[] multipartFiles,@RequestParam("side") String[] sides) 
     throws Exception { 
    return AppointmentService.uploadFileImage(multipartFiles, sides); 
} 

,但我無法發送的String []方通過更改上述代碼到該服務。 要求我的服務是一樣的東西

"Token:[email protected]:people:1460612590421:3f8eeae2f6d2a53c18117bca8952d018" -H "Content-Type:multipart/form-data" "myURL/appointment/myImages" -X POST -F [email protected]/home/ulhas/Desktop/desktopPdata/img_195753.jpg -F side=left -F [email protected]/home/ulhas/Desktop/desktopPdata/img_195753.jpg -F side=left 

回答

0

試試這個代碼..

private class webAsync extends AsyncTask<String, Integer, String> { 

    private ProgressDialog pb = null; 
    private HttpResponse httpResponse; 
    private HttpPost postRequest; 
    private HttpClient httpClient; 
    private HttpEntity httpEntity; 
    String Str_imagepath="path file"; 

    @Override 
    protected String doInBackground(String... params) { 



     String APP_SERVICE_DOMAIN = null; 
     String mIncomingUrl = null; 

      APP_SERVICE_DOMAIN = "URL webservice"; 

     mIncomingUrl = APP_SERVICE_DOMAIN;// add the field if any 




     System.out.println("@Incoming Request URL ==" + mIncomingUrl); 
     try { 

      HttpPost httppost = new HttpPost(mIncomingUrl); 

      MultipartEntity entity = new MultipartEntity(); 
      File myFile = new File(Str_imagepath); 
      Log.e("TAG_FILE", "Exists1 " + myFile.exists()); 

      FileBody fileBody = new FileBody(myFile); 
      if(myFile.exists()) { 
       entity.addPart("image", fileBody); 

    // webservice parameter for file 
      } 
     for (String mArray: mSelectedCategoryArray) 
     { 
    entity .addPart("ArrayID[]", new StringBody(mArray)); 
     } 

      httppost.setEntity(entity); 
      HttpClient httpclient = new DefaultHttpClient(); 
      HttpResponse httpresponse = httpclient.execute(httppost); 
      if (httpresponse.getEntity() != null) { 
       String fileResponse = EntityUtils.toString(httpresponse 
         .getEntity()); 
       System.out.println("@@............." + fileResponse); 



       return fileResponse; 
      } 
     } catch (Exception e) { 


     } 

     return null; 
    } 


} 
+0

阿瓊我需要發送「文件」,也即的String []類型。檢查我的服務要求。 –

+0

我在我的Android新能有所幫助與MultipartEntity ---添加> 爲(字符串MARRAY:mSelectedCategoryArray){ 實體.addPart( 「的ArrayID []」,新StringBody(MARRAY)); } –

+0

請參閱編輯答案...如果有幫助 –

相關問題