tomjung tomjung - 1 year ago 78
PHP Question

Android volley is sending information twice with image upload

I am trying to send an image with my post data to my server from android. To accomplish this I base 64 encoded my image to string and sent it using the android volley library. This is causing problems though. For some reason it sometimes sends the post twice, and I cannot figure out why. Below is the function that is called to send the post request. I put a break mark at the

String url = "";
and then one at the
protected Map<String, String> getParams() {
What I found is the
String url = ...
is only being called once but when it sends two, the
protected Map...
is called twice. I can't find any documentation on the android volley so I don't know why this is happening. The bitmap is resized so the image string is somewhere between 100k and 200k characters consistently. I thought maybe it was a size issue but my server is receiving the images and decoding them and everything just fine.

public void Sharing() {

pd =, null, "Please Wait...");
final String caption = mEtMessage.getText().toString();
RequestQueue queue = Volley.newRequestQueue(this);
String url = "";
StringRequest postRequest = new StringRequest(
new MyStringListener(),
new MyErrorListener()
) {
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("token", "secretToken");
params.put("mode", "createVoucher");
params.put("deal_id", ActivitySharing.id_deal);
params.put("user_id_company", ActivityRestaurantDetails.res.getId());
params.put("user_img", pathImage);
params.put("caption", caption);
params.put("company_id", ActivityRestaurantDetails.res.getId());
return params;


Any idea why this might be happening?

Answer Source

Volley uses a RetryPolicy for processing requests which by defaults sends the request up to 3 times with an exponential backoff algorithm. Can it be that some request fail and are retried ? Do you get any error/success logs for the first call of the request ?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download