【问题标题】:While uploading image to server (error while uploading)将图像上传到服务器时(上传时出错)
【发布时间】:2016-12-23 17:53:18
【问题描述】:

在我的应用程序中,我将 3 个参数发送到服务器纬度、经度和图像。之前我使用 volley 发送参数,但由于我有图像,所以我必须在代码中使用 Multipart。但我收到错误上传时。在通知栏中,上传开始,但过了一段时间它说上传错误
下面是 MultiPart 的代码:

public void send() {
            try {
                String uploadId = UUID.randomUUID().toString();


                //Creating a multi part request
                new MultipartUploadRequest(this, uploadId, REGISTER_URL)
                        .setMethod("POST")
                        .addParameter("action", "location")
                        .addFileToUpload(imagePath, "data")//Adding file
                        //.addParameter("name", name) //Adding text parameter to the request
                        .setNotificationConfig(new UploadNotificationConfig())
                        .setMaxRetries(5)
                        .startUpload(); //Starting the upload

            } catch (Exception exc) {
                Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }

以下是我的截击代码:

    final String latitudee = String.valueOf(latitude);
    final String longitudee =String.valueOf(longitude);
    final String datae = imagePath;
    //getting the actual path of the image

   StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Toast.makeText(MapsActivity.this,response,Toast.LENGTH_LONG).show();
                    System.out.println(response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(MapsActivity.this,error.toString(),Toast.LENGTH_LONG).show();
                }
            }){
        @Override
        protected Map<String,String> getParams(){
            Map<String,String> params = new HashMap<String, String>();
            params.put("action","location");
            params.put("latitude",latitudee);
            params.put("longitude",longitudee);
            send();
           // params.put("data", datae);
            //Uploading code




            return params;}
    };

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}

请帮我看看哪里出错了

【问题讨论】:

    标签: image file-upload server android-volley multipartentity


    【解决方案1】:

    您也可以通过 Multipart 请求库发送您的其他参数。只需添加“添加参数”即可发送更多参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-12
      • 1970-01-01
      相关资源
      最近更新 更多