1
我忙于一个小型的android应用程序。应用程序使用restful连接到WCF,然后连接到数据库。该应用程序确实有效。现在我想将图像发送到数据库。使用URI编码图像
[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一个问题,因为它拿起/
作为参数的变化,从而拾取,它不是一个有效的请求。有没有办法在不影响解码的情况下移除/
或者有没有更好的方法将图像转换为字符串并返回到图像?
谢谢,我没有想到做选项二。比选项1的开销少。 – Jonathan 2014-10-05 16:00:50