Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read image into protorpc message thru endpoints api

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)
like image 287
Katedral Pillon Avatar asked Jan 14 '23 21:01

Katedral Pillon


1 Answers

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)
like image 126
bossylobster Avatar answered Jan 21 '23 19:01

bossylobster