Reputation: 14864
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)
Upvotes: 4
Views: 1331
Reputation: 10163
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)
Upvotes: 9