I am trying to make a post request in my android app to an external flask app with Volley and a MultipartEntity but the flask app is taking too long to respond and the Response.ErrorListener is getting called. I want to lengthen the timeout of the Response so the flask side has the time it needs to respond.
This is my MultipartEntity code:
public MultipartRequest(String url, Response.ErrorListener errorListener,
Response.Listener<String> listener, File file, String stringPart)
{
super(Method.POST, url, errorListener);
mListener = listener;
mFilePart = file;
mStringPart = stringPart;
buildMultipartEntity();
}
private void buildMultipartEntity()
{
entity.addPart(FILE_PART_NAME, new FileBody(mFilePart));
}
@Override
public String getBodyContentType()
{
return entity.getContentType().getValue();
}
@Override
public byte[] getBody() throws AuthFailureError
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try
{
entity.writeTo(bos);
}
catch (IOException e)
{
VolleyLog.e("IOException writing to ByteArrayOutputStream");
}
return bos.toByteArray();
}
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response)
{
return Response.success("Uploaded", getCacheEntry());
}
@Override
protected void deliverResponse(String response)
{
mListener.onResponse(response);
}
}
This is my send image function using that code:
public void sendImg(View v){
File pic = (File) getIntent().getExtras().get("pic");
String str = "img";
MultipartRequest multipartRequest = new
MultipartRequest("http://100.64.113.81/digitize",
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("img", "That didn't work!");
}
},
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("server", response);
}
}, pic, str);
RequestQueue queue = Volley.newRequestQueue(this);
queue.add(multipartRequest);
}
Thanks so much for your help.