0

I want to upload image file with help of volley (POST).
my request is already working and i made JSONObject and can connect to url and post title and description for my data.
now i want to add image with it in next level using MultipartEntity.
I already red several post in https://stackoverflow.com/ but did not get anywhere. my schedule is a bit tight and need your help.
any help would be appreciated.thank you all in advance.

    public void postData(Context applicationContext, String title, String note, String imagePath , String imageDescription, final Listeners.APIPostDataListener listener) {
    //Instantiate the RequestQueue.
    RequestQueue queue = Volley.newRequestQueue(applicationContext);
    Settings settings = new Settings(applicationContext);
    String selectedURL = settings.getChosenUrl();
    final String token = settings.getTokenKey();
    String url = "http://" + selectedURL + "/databox/api/v1/upload/files";
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("Content-Disposition", "form-data");
    File file = new File(imagePath);

    try {
        MultipartRequest mr = new MultipartRequest(url, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                Log.d("response", response);
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("Volley Request Error", error.getLocalizedMessage());
            }

        }, file, params){
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> params = new HashMap<String, String>();
                params.put("Authorization", "Bearer " + token);
                //params.put("Content-Type", "multipart/form-data");
                return params;
            }
        };
        queue.add(mr);
    }catch(Exception exception){
        Log.e("postData",exception.getMessage());
    }

I changed the code , now I am getting server error.

Community
  • 1
  • 1
S.D.H.Z
  • 57
  • 8

0 Answers0