【问题标题】:Using Google Cloud Datastore and AJAX(blobs)-python使用 Google Cloud Datastore 和 AJAX(blob)-python
【发布时间】:2011-05-09 19:33:37
【问题描述】:
您好,我有一些图像作为 BlobProperty 存储在 Google Cloud Datastore 中。我正在尝试通过 ajax 将这些图像加载到我的模板中。例如:- 用户有图像和名称。现在图像和名称区域通过对服务器的 AJAX get 调用填充。我不明白如何将这些图像发送到客户端,JSON 不支持二进制数据。然而,谷歌搜索告诉我一个叫做 base 64 的东西。(我对这一切都很陌生,所以让我承认,我是一个菜鸟)。
这是处理这个问题的唯一方法还是有其他更好的方法。
【问题讨论】:
标签:
javascript
python
google-app-engine
flask
google-cloud-datastore
【解决方案1】:
我就是这样做的,它在烧瓶中,但它仍然是 python
这样,您就可以创建一个请求处理程序来显示图像。
因此,通过 ajax 获取图像所需要做的就是获取要提供的图像 ID。它更简单,您也可以动态调整大小
from flask import request
from google.appengine.api import taskqueue, images, mail
from google.appengine.ext import db
@app.route('/image/<img_id>')
def imgshow(img_id):
imageuse = Image.all().filter("image_id =", img_id).get()
if imageuse:
response = Response(response=imageuse.content)
#you can use any type over here
response.headers['Content-Type']='image/png'
return response
else:
return
这就是我用来控制大小的方法
@app.route('/thumb/<img_id>')
def thumbshow(img_id):
imageuse = Image.all().filter("image_id =", img_id).get()
if imageuse:
thbimg = images.resize(imageuse.content, 80)
response = Response(thbimg)
response.headers['Content-Type']='image/png'
return response
else:
return
希望对你有帮助