大家好我想把图片发布到db.Here我发布了一个从android客户端到DB.Spring的图像MVC REST Web服务是mid layer.can你请建议我如何发布图像byte []值到来自android客户端的db。提前感谢您的宝贵建议。
答案 0 :(得分: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;
}