0

Hi guys I am trying to post image to db.Here I am posting an image from android client to DB.Spring MVC REST web services is the mid layer.can you please suggest me how to post image byte[] value to db from android client. Thanks in advance for your valuable suggestions.

Hits
  • 71
  • 1
  • 8

1 Answers1

0

you can use MultipartEntity

    public static HttpResponse sendImage(byte[] image) {
    HttpResponse responsePOST = null;
    try {
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(postURL+"user_profile");
        post.setHeader("Accept", "application/json");                                   
        ByteArrayBody bab = new ByteArrayBody(image, firstname+".png");
        MultipartEntity reqEntity = new MultipartEntity(
                HttpMultipartMode.BROWSER_COMPATIBLE);          
        reqEntity.addPart("user_profile[image_attributes[attachment]]", bab);           

        post.setEntity(reqEntity);                      
        responsePOST = client.execute(post);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return responsePOST;
}
Sanu
  • 455
  • 1
  • 6
  • 17
  • http://stackoverflow.com/questions/12422541/how-to-send-multiple-images-to-server-using-multipartentity-from-android – Sanu Apr 04 '14 at 06:44