How to upload image using volley android in MVC api post method

How to upload image using volley android in MVC api post method.I tried this:

  StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String responec) {
                    loading.dismiss();
                    Log.e("tag","data :"+responec);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    loading.dismiss();
                    Log.e("tag","data :"+volleyError.toString());
                }
            }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            String image = getStringImage(bitmap);
            Map<String,String> params = new Hashtable<String, String>();
            params.put(KEY_IMAGE, image);
            return params;
        }
    };
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);

      

how can i handle this.

+3


source to share


1 answer


For me, I always base64 bitmap using

public static String encodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality)
{
    ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
    image.compress(compressFormat, quality, byteArrayOS);
    return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT);
}

      

then post base64 to your API,



in reverse mode decodes base64 and shows the image using

public static Bitmap decodeBase64(String input)
{
    byte[] decodedBytes = Base64.decode(input, 0);
    return BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
}

      

ImageViewObject.setImageBitmap();

-1


source







All Articles