I am trying to upload an image from android to asp.net mvc webapp. I've the following code to upload image on android part -
public String getStringImage(Bitmap bmp){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
return encodedImage;
}
private String UPLOAD_URL ="UploadSignature?id=1";
private String KEY_IMAGE = "image";
private String KEY_NAME = "name";
private Bitmap bitmap;
private void uploadImage(){
StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
String image = getStringImage(bitmap);
String name = "firstImage";
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);
}
In asp.net mvc controller-
[HttpPost]
public ActionResult UploadSignatureTwo(byte[] Data)
{
System.IO.File.WriteAllBytes( @"D:\test.jpg", Data);
}
But it says Data can not be null
.
Any help?