android图像上传到快速基础数据库

时间:2012-04-04 13:21:08

标签: java android

我正在开发一个Android应用程序,根据快速基础API上传图像到快速基础数据库(https://www.quickbase.com),图像应该以base64格式上传,它应该通过xml格式的帖子发送请求并且不允许MIME标头和类型(http://www.quickbase.com/api-guide/whnjs.htm)。每个文本数据都会进入数据库,但图片没有上传到服务器,这是我的代码,有人可以给我一个帮助吗?

String tempXml = "<?xml version='1.0' ?><qdbapi><udata>mydata</udata>"
+ "<ticket>6_bg4at2ksw_bzazsh_b_cmti6qddhsrvgqds7cqmgbt32t6wcdkcse2c8j8ypyb</ticket>"
+ "<apptoken>cwfcy7gdzqrsyncqbi2bn4u4kr</apptoken>"
+ "<field fid='6'>sample data</field><field fid='7'>sample data</field>"
+ "<field fid='8'>sample data</field><field fid='9'>sample data</field>"
+ "<field fid='10'>sample data</field><field fid='12'>sample data</field>"
+ "<field name='message' filename='testImage.jpg'>"
+ testImageName + "</field></qdbapi>";

DefaultHttpClient httpclient = new DefaultHttpClient();
String strURL = "https://www.quickbase.com/db/bgtc5pacu?act=API_AddRecord";
HttpPost httpPost = new HttpPost(strURL);
httpPost.addHeader("Content-Type", "application/xml");
StringBuilder sb = new StringBuilder();
sb.append(tempXml);
StringEntity entity = new StringEntity(sb.toString(), "UTF-8");
httpPost.setEntity(entity);
HttpResponse res = httpclient.execute(httpPost);

1 个答案:

答案 0 :(得分:0)

使用base64类从图像的字节数组中获取base64字符串。

base64.java

方法名称:encodeBytes(byte [] source)