Hy guys!
I have a jpg image stored on my device
and I want to sent it to server
(mywebsite.com/api.php). I would like to use volley library
because it is made by official android developers from google and I think they will add it to the sdk as soon as possible.
Right now I am using the folowing 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 could I send the jpg to server with volley library? Every time I send something I need to send it together with the API key in order to receive information to server, so I cant change Map<String, String>
to Map<String, File>
because my API key is a string.
I have read that there is a solution to change my image to a byte[] array
and then converting it to a base64 string
format, but I would want to avoid this if possible.
Is there any other solution to send the image without converting it to a base64 string
?
Any reference or advice is welcome! Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…