Guy guys!
I have a jpg image stored on my device and I want sent it to server (mywebsite.com/api.php). I would like to use the volley library because it is made by official Android developers from Google, and I think they will add it to sdk as soon as possible.
Now I use the following code to send strings to the server:
postRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { try { // code here for response } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // code here for error response } } ) { @Override protected Map<String, String> getParams() { Map<String, String> params = new HashMap<>(); // the POST parameters: params.put("key", "myApiKey"); params.put("data","stringOfMyData"); return params; } };
How can I send jpg to a volleyball library server? Every time I send something, I need to send it along with the API key in order to receive information on the server, so I can not change Map<String, String> to Map<String, File> , because my API key is this is a string.
I read that there is a solution to change my image to a byte[] array and then convert it to a base64 string format, but I would like to avoid this if possible.
Is there any other solution for sending an image without converting it to a base64 string ?
Any recommendations or tips are welcome! Thanks in advance!
source share