While uploading image to server (error while uploading)

293 views Asked by At

In my app I m sending 3 parameters to server latitude,longitude and image.Earlier i was using volley for sending the parameter, but since i have a image also I had to use Multipart in my code.But i m getting an error while uploadind. In the notification bar the uploading starts but after some times it says error in uploading
Below is the code for 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();
            }
        }

Below is my volley code:

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

Please help me where I'm going wrong

1

There are 1 answers

0
Priyanka On

You can send your others parameters through Multipart request library too. just add "add parameter" to send more parameters.