【发布时间】:2014-11-30 00:11:01
【问题描述】:
我正忙于一个小的安卓应用程序。该应用程序使用 restful 连接到 WCF,而后者又连接到数据库。该应用程序确实有效。现在我想将图像发送到数据库。
[OperationContract]
[WebGet(UriTemplate = "sendImage/{seq}", ResponseFormat = WebMessageFormat.Json)]
string sendImage(string seq);
在 android 应用程序中,我使用 BASE64 对图像进行编码。
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
TextView textView = (TextView) findViewById(R.id.defaults);
textView.setText(encodedImage);
这种加密确实有效。问题是我现在将字符串encodedImage 发送到WCF 以写入数据库。因此,字符串在 URI 中传递。
"htp://_____.__/serv/ManagementSystem.svc/sendImage/" + encodedImage
问题是我从编码中得到的字符串包含/ 字符。
/9J/DASDFkFASDF/.....
这会导致 URI 出现问题,因为它会将 / 作为参数更改,因此会发现它不是一个有效的请求。有没有办法在不影响解码的情况下删除/,或者有没有更好的方法将图像转换为字符串并返回图像?
【问题讨论】:
标签: android encoding base64 decoding