现在的位置: 首页 > 综合 > 正文

xutils上传多图片

2018年04月27日 ⁄ 综合 ⁄ 共 2009字 ⁄ 字号 评论关闭


// 多图片
 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);
       }
      });

   }

抱歉!评论已关闭.