zed*_*dix 2 java google-app-engine android google-cloud-endpoints google-cloud-datastore
我有一个GAE +端点在Android客户端和应用引擎后端之间工作.
我现在正处于使用JDO将小图像存储为Blob数据类型的位置.我的模型的后端有以下两种方法:
public byte[] getPicture() {
if (picture == null) {
return null;
}
return picture.getBytes();
}
public void setPicture(byte[] bytes) {
this.picture = new Blob(bytes);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我为Android客户端生成端点时,setPicture(byte [] bytes)方法签名将转换为setPicture(String bytes).
这是一个错误还是打算?如果打算,我该如何将我的图像转换为字符串?
谢谢!
好吧,我明白了.原来它期望base64格式的字节数组,这解释了为什么byte []签名变为String.
所以在Android中我从byte []转到我使用的base64字符串,其中mPicture是我的字节数组:
Base64.encodeToString(mPicture, Base64.DEFAULT);
Run Code Online (Sandbox Code Playgroud)
并接收一个String并转换回byte [],其中picture是从端点接收的base64字符串:
Base64.decode(picture, Base64.DEFAULT);
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
792 次 |
| 最近记录: |