尝试使用AndroidAsyncHttp无法正常上传图片

时间:2016-04-20 06:39:02

标签: java android

我们正尝试使用AsyncHttpClient库上传图像和其他字符串。以下是我们迄今为止所做的事情:

AsyncHttpClient client = new AsyncHttpClient();
                        RequestParams params = new RequestParams();
                        params.put("userId", user_id);
                        params.put("proofDocId", idproofno);
                        params.put("proofFilename",proofFilename);
                        params.put("docType", docType);
                        try {
                            params.put("proof",new File(img_path));
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
                      client.post(Constants.UPLOAD_URL,params,new JsonHttpResponseHandler(){
                          @Override
                          public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                              super.onSuccess(statusCode, headers, response);
                              if(progressDialog.isShowing()) {
                                  progressDialog.dismiss();
                              }
                              String status = response.toString();
                              Toast.makeText(getApplicationContext(), status, Toast.LENGTH_LONG).show();
                          }

                          @Override
                          public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                              super.onFailure(statusCode, headers, responseString, throwable);
                          }
                      });

img_path字符串是设备上图像的位置。以这种方式返回JSON响应,表明找不到图像。但是我们在Instagram上的POSTMAN rest客户端上尝试了相同的Web服务和文件上传工作正常。为什么图像/文件没有上传?请帮助。

0 个答案:

没有答案