Reputation: 3234
I am letting the user select a image and then the image will be converted to Base64. I am trying to append the Base64 String to my url(Json Format) like in the below
http://codemoirai.esy.es/register.php?UserDetails={"Sex":"Male","Username":"joes","Bitmap":"iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAIAAAA2NdDLAAAAA3NCSVQICAjb4U\/gAAAgAEl......
But i am getting a error like this:
BasicNetwork.performRequest: Unexpected response code 414 for http://codemoirai.esy.es/register.php?UserDetails={"Sex":"Male","Username":"joes","Bitmap":"iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAIAAAA2NdDLAAAAA3NCSVQICAjb4U\/gAA...........
Can i know what is causing this error? How can send a image file which is encoded to Base64 format using Volley?
ThankYou
Upvotes: 1
Views: 3650
Reputation: 7532
Response code 414 is Request-URI Too Long (Your base64 image string is too long to put in url).
The server is refusing to service the request because the Request-URI is longer than the server is willing to interpret. This rare condition is only likely to occur when a client has improperly converted a POST request to a GET request with long query information, when the client has descended into a URI "black hole" of redirection (e.g., a redirected URI prefix that points to a suffix of itself), or when the server is under attack by a client attempting to exploit security holes present in some servers using fixed-length buffers for reading or manipulating the Request-URI.
So you should change from http get to http post and send base64 image in http body
Your server must handle http post data. I dont know what language you use to implement your server side. So i only post client sample Sample
public void uploadAvatar(String username,String sex, String accessToken, String image, Response.Listener<JSONObject> success, Response.ErrorListener error) {
String endpoint = "your server api url";
ScoinJsonRequest request = new ScoinJsonRequest(Request.Method.POST, endpoint, getuploadAvatarParams(user, sex, image), success, error);
request.setRetryPolicy(new DefaultRetryPolicy(MY_SOCKET_TIMEOUT_MS, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(request);
}
private Map<String, String> getuploadAvatarParams(String username,String sex,String stringBase64)
{
Map<String, String> params = new HashMap<String, String>();
params.put("username", username);
params.put("gender", sex);
params.put("ibase64", stringBase64);
return params;
}
Then you can use uploadAvatar function and input all the required params.
About server side you can search read http post data + your language
. I give you a link to c# example
Upvotes: 2