2014-04-04 35 views
0

嗨,大家好我想圖像發佈到db.Here我張貼圖像從Android客戶端到DB.Spring MVC REST Web服務是中間層。你請建議我如何將圖像byte []值從Android客戶端發佈到數據庫。預先感謝您的寶貴建議。如何發佈圖像byte []值到數據庫在春天mvc

回答

0

可以使用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; 
} 
+0

您能否提供我任何教程,Android的.. – Hits

+0

http://stackoverflow.com/questions/19738594/multipartentity-post-android – Sanu

+0

http://chrislee.kr/wp/tag/multipartentity-example-android/ – Sanu