4

To receive a picture from a user into my @endpoints.method do I use messages.BytesField as in

image = messages.BytesField(1)
stuff = messages.StringField(2)
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199

1 Answers1

9

Yes, this is the right strategy. When using Cloud Endpoints, the bytes sent to a BytesField must be base64 encoded.

After being sent and validated through Google's API infrastructure, the base64 encoded bytes will be sent along to your protorpc.remote.Service class and converted from a base64 string to a native byte-string (instance of str) in Python.

So you'll need your clients to take the image bytes and convert them to base64.

To encode a byte string as base64 in Javascript, see How can you encode a string to Base64 in JavaScript?, to do the same in Python, simply call

import base64
base64.b64encode(byte_string)
Community
  • 1
  • 1
bossylobster
  • 9,993
  • 1
  • 42
  • 61
  • Thanks for the base64 encoding bit. Say, to send a blob from app-engine to the front-end (here android), must I also encode the blob somehow or do I just send it? – Katedral Pillon Apr 10 '13 at 00:21
  • 1
    @KatedralPillon feel free to ask more questions. You can just set the blob as the value of the `BytesField` and when it is served by Endpoints it will be base64 encoded. – bossylobster Apr 14 '13 at 16:49