嗨,我有一些图像作为BlobProperty存储在谷歌云数据存储中。我正在尝试通过ajax将这些图像加载到我的模板中。例如:-用户有一个图像和一个名字。现在,通过对服务器的AJAX get调用填充了图像和名称区域。我不知道如何将这些图像发送到客户端,JSON不支持二进制数据。然而,在谷歌上搜索一下,我发现了一种叫做base64的东西。(我对这一切都很陌生,所以让我承认,我是一个新手)。
这是解决这个问题的唯一方法,还是有其他更好的方法。
发布于 2010-11-14 20:57:07
此线程建议,如果您只是创建一个图像元素,设置其src,并使用Javascript将其添加到您的页面,浏览器将负责对图像进行HTTP请求:
http://bytes.com/topic/javascript/answers/472046-using-ajax-xmlhttprequest-load-images
如果你确实想使用‘纯’AJAX,那么base64可能是最好的选择:它是一种将二进制数据(如图像)编码为文本的方式,因此你可以在json中将其作为长字符串发送。
发布于 2012-01-04 15:13:35
这就是我怎么做的,它是在flask中的,但不管怎样,它是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希望这能有所帮助
https://stackoverflow.com/questions/4177492
复制相似问题