2016-05-13 58 views
0

我在寫doInBackground下面的代碼,發送多個圖像路徑到服務器?

InputStream in = null; 
DefaultHttpClient httpclient = new DefaultHttpClient(); 
try { 
    System.out.println("calling API here"); 
    HttpPost httppost = new HttpPost("my url"); 
    MultipartEntity reqEntity = new MultipartEntity(); 

    if (imageList != null) { 
     for(int i=0;i<imageList.size();i++) { 

      File f= new File(imageList.get(i)); 
      in = new BufferedInputStream(new FileInputStream(f)); 
      reqEntity.addPart("file[]",f.getName(), in);  

      } 
     } 

    reqEntity.addPart("mobile",owner_mobile); 
    reqEntity.addPart("reg_code",reg_code); 
    reqEntity.addPart("book_id",book_id); 
    reqEntity.addPart("adv_amount",advAmountValue); 

    httppost.setEntity(reqEntity); 

    HttpResponse response = httpclient.execute(httppost); 

問題是,當我派multiple image(s)server,只有第一個圖像(for e.g, 23457352.jpg)派遣有些則沒有。

任何人都可以幫我解決這個問題嗎? 在此先感謝...

+0

是你的完整代碼嗎?你已經關閉了'try'和'if'語句。 –

回答

0

嘗試在屬性名稱中使用索引。

for(int i=0;i<imageList.size();i++){ 

           File f= new File(imageList.get(i)); 
           in = new BufferedInputStream(new FileInputStream(f)); 
           reqEntity.addPart("file[" + i + "]",f.getName(), in);  

           } 
          } 
+0

我得到同樣的結果。這裏我的ArrayList imageList包含3的大小,但只有一個圖像路徑發送到服務器。 – pb123