Application engine + endpoint generating string instead of byte array as method argument

I have GAE + endpoints running between android firewall and app client.

Now I am 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 backend:

public byte[] getPicture() {
    if (picture == null) {
        return null;
    }
    return picture.getBytes();
}

public void setPicture(byte[] bytes) {
    this.picture = new Blob(bytes);
}

      

However, when I create my endpoint for my Android client, the method signature of setPicture (byte [] bytes) is converted to setPicture (string bytes).

Is this a mistake or intention? If it is supposed, how should I wrap my image onto a string?

Thank!

+2


source to share


1 answer


Ok I figured it out. It turns out that it expects a base64 formatted byte array, which explains why the byte [] signature changes to a string.

So, in Android, to go from byte [] to base64 string I used, where mPicture is my byte array:

Base64.encodeToString(mPicture, Base64.DEFAULT);

      



And get a String and convert back to byte [] where the image is the base64 string received from the endpoint:

Base64.decode(picture, Base64.DEFAULT);

      

Hope this helps!

+5


source







All Articles