I am using Volley to make server requests but i came to know that volley is not passing params from getParams() method in POST request, so now i am passing these data by concatenating all param/values with the url like bellow.
String url = "http://myweb/api/work?"+param1+"="+value;
Now the problem is it works fine with text data only, i can make request successfully and all params are passing to server but now i have to upload some image file also using same api.
How can i pass a file and string data using Volley POST method?
Following are the solutions i tried but got no success. https://gist.github.com/anggadarkprince/a7c536da091f4b26bb4abf2f92926594#file-volleymultipartrequest-java
https://www.simplifiedcoding.net/android-volley-tutorial-to-upload-image-to-server/
Edit Following is my current request code:
StringRequest request = new StringRequest(Request.Method.POST, uri + param, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
dismissProgressDialog();
printResponse(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
dismissProgressDialog();
error.printStackTrace();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<>();
headers.put("key", key);
headers.put("tkey", tkey);
headers.put("Content-Type", "application/multipart");
return headers;
}
};