应用程序引擎+终端生成字符串,而不是字节数组作为方法参数 [英] App engine + endpoint generating a string instead of byte array as method argument
问题描述
我GAE +端点的Android客户端和应用程序引擎的后端之间的工作。
I have GAE + endpoints working between an Android client and app engine backend.
我现在在哪里我想一个小图像存储为使用JDO的Blob数据类型的地步。我在我的模型的后端以下两种方法:
I'm now at the point where I want to store a small image as a Blob datatype using JDO. I have the following two methods in my model's backend:
public byte[] getPicture() {
if (picture == null) {
return null;
}
return picture.getBytes();
}
public void setPicture(byte[] bytes) {
this.picture = new Blob(bytes);
}
然而,当我产生我的端点我的Android客户端,setPicture(字节[]字节)的方法签名被转化为setPicture(字符串的字节)。
However, when I generate my endpoint for my Android client, the setPicture(byte[] bytes) method signature gets transformed to setPicture(String bytes).
那是一个错误或故意的吗?如果打算,我怎么给我的图像传送到一个字符串?
Is that a bug or intended? If intended, how am I supposed to transfer my image to a String?
谢谢!
推荐答案
好吧,我想通了。原来,该公司预计,以base64格式的字节数组,这也解释了为什么字节[]签名得到改变后的字符串。
Alright, I figured it out. Turns out it's expecting the byte array in base64 format, which explains why the byte[] signature gets changed to a String.
因此,在Android的从字节[]为Base64字符串我用,其中mPicture是我的字节数组去:
So in Android to go from byte[] to base64 string I used, where mPicture is my byte array:
Base64.encodeToString(mPicture, Base64.DEFAULT);
和接收字符串和转换回为byte [],其中图片是从端点收到的base64字符串:
And to receive a String and transform back to byte[], where picture is the base64 string received from endpoint:
Base64.decode(picture, Base64.DEFAULT);
希望这有助于!
这篇关于应用程序引擎+终端生成字符串,而不是字节数组作为方法参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!