xutils上传多图片



// 多图片
 private String uploadHost2 = "http://IP:8080/ajax/attach.php?ssotoken="+ ssotoken + "&act=uploadpic";


//图片本地sd卡地址链接

String[] filePaths = { filePath1,filePath2,filePath3,filePath4};


 /** 上传图片 */
   private void upPics() {

    RequestParams params = new RequestParams();
    for (int i = 0; i < filePaths.length; i++) {
     params.addBodyParameter("attach[" + i + "]", new File(
       filePaths[i]), "image/jpeg");
    }

    uploadMethod(params, uploadHost2);

   }



private void uploadMethod(RequestParams params, String uploadHost) {

    HttpUtils http = new HttpUtils();
    http.send(HttpRequest.HttpMethod.POST, uploadHost, params,
      new RequestCallBack<String>() {
       @Override
       public void onStart() {
        // msgTextview.setText("conn...");
       }

       @Override
       public void onLoading(long total, long current,
         boolean isUploading) {
        if (isUploading) {
         Log.v("logcat", "upload: " + current + "/"
           + total);
         // msgTextview.setText("upload: " + current
         // + "/" + total);
        } else {
         Log.v("logcat", "reply: " + current + "/"
           + total);
         // msgTextview.setText("reply: " + current
         // + "/" + total);
        }
       }

       @Override
       public void onSuccess(
         ResponseInfo<String> responseInfo) {
        String result = responseInfo.result;
        
        Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
        Log.v("logcat", "result=" + result);
        try {
         JSONObject json = new JSONObject(result);
         if (json.getInt("code") == 0) {
          JSONArray json2 = json
            .getJSONArray("data");
          for (int i = 0; i < json2.length(); i++) {
           listAid.add(json2.getJSONObject(i)
             .getString("aid"));

          }

         }

        } catch (JSONException e) {
         Log.e("JSONException", e.getMessage());
         e.printStackTrace();
        }

        //faBu();

       }

       @Override
       public void onFailure(HttpException error,
         String msg) {

        Log.d("logcat",
          "error:" + error.getExceptionCode()
            + ":" + msg);
       }
      });

   }

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值