将图像上传到服务器时(上传时错误)



在我的应用中,我将3个参数发送到服务器纬度,经度和图像。我的代码。但是我在上传时遇到错误。在通知栏中,上传开始,但是一段时间后,它在上传时说明了错误
以下是多部分的代码:

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

请帮助我在哪里出错

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

相关内容

  • 没有找到相关文章

最新更新