【发布时间】:2016-09-24 16:17:48
【问题描述】:
我有以下 GET 方法的代码,该方法拍摄一张照片,该照片存储在 MySql 的 blob 类型字段中并返回。我想在一个 JSON 字符串中将它返回给客户端,它可以在 angularjs 应用程序中显示图像。
def GET(self,r):
user_data = CC.get_data(query) # holds the content of the blob field.
print type(user_data) # prints <type 'str'>
data = {'name': 'test',
'photo': user_data}
return json.dump(data)
这给了,
UnicodeDecodeError: 'utf8' codec can't decode byte 0x89 in position 0:
invalid start byte
我在一些网站上发现最好将照片作为字节数组发送。 我使用 web.py python 框架。 最好的方法是什么?
【问题讨论】:
标签: python mysql json rest blob