質問

I am making a post from android to php with data and an image. I'm scaling the image down in android and base 64 encoding it. When it is sent via volley, most images are somewhere between 70 and 100kbs. The problem I have is that a few images for whatever reasons come out to be slightly bigger, like 130kbs. At 130kbs, the volley doesn't get a response soon enough and send the request again, creating multiple entries on my database. 30Kb's seems like a very small window, so I need to put a safety measure in place to prevent multiple entries.

I'm not sure what the best approach to solving this problem is. Is there a way to extend the initial wait period in volley? Can I handle the decoding of the image and saving on the php server asynchronously so not to slow down the response? Should I do a check to make sure the incoming request is not a duplicate?

Please let me know what you think the best solution is and why.

役に立ちましたか?

解決

Use setRetryPolicy method which receives a DefaultRetryPolicy object, so you can pass an instance with custom values:

myVolleyRequest.setRetryPolicy(new DefaultRetryPolicy(initialTimeoutMs, maxNumRetries, backOffMultiplier));

Hope it helps.

他のヒント

I don't know if Volley allows to set timeouts directly, but maybe you could use okhttp over volley. This is known to work well, and okhttp has a very clear API that will let you set both connect and read timeouts easily.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top