read image into protorpc message thru endpoints api

非 Y 不嫁゛ 提交于 2019-12-07 11:12:49

问题


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)

回答1:


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)


来源:https://stackoverflow.com/questions/15576203/read-image-into-protorpc-message-thru-endpoints-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!