【问题标题】:sending multiple image path to the server?向服务器发送多个图像路径?
【发布时间】:2016-05-13 13:14:28
【问题描述】:

我在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) 正在发送其他人不是。

谁能帮我解决这个问题? 提前谢谢...

【问题讨论】:

  • 那是你的完整代码吗?您有未关闭的tryif 语句。

标签: android asynchronous http-post androidhttpclient


【解决方案1】:

尝试在属性名中使用索引。

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

                                }
                            }

【讨论】:

  • 我得到了相同的结果。这里我的 ArrayList imageList 包含大小 3 ,但只有一个图像路径发送到服务器。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多