I try to use Volley
library and upload image to server. This library should do this process in standalone mode, but have got following error message:
java.net.SocketException: sendto failed: ECONNRESET (Connection reset by peer)
Is it maybe a server side misconfiguration?
I try to upload a jpeg
image with this code:
private void uploadImage(){
final ProgressDialog loading = ProgressDialog.show(this,"Uploading...","Please wait...",false,false);
StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
loading.dismiss();
Toast.makeText(PhotoActivity.this, s , Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
loading.dismiss();
Toast.makeText(PhotoActivity.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
String image = getStringImage(bitmap);
String name = editTextName.getText().toString().trim();
Map<String,String> params = new Hashtable<String, String>();
params.put(KEY_IMAGE, image);
params.put(KEY_NAME, name);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
just to be sure, you need to change your
uploadImage()
into something like this:Where your
ImageUploadRequest
class is defined as demonstrated in the accepted answer here like this:I have made some minor adaptations of Upload an image using Google Volley to your specific situation. I hope this helps you and that others may also find it useful.