0

您好我有一些图像存储为谷歌云数据存储BlobProperty。我正尝试通过ajax将这些图像加载到我的模板中。例如: - 用户有一个图像和一个名字。现在,图像和名称区域将通过AJAX get调用填充到服务器。我不知道如何将这些图像发送到客户端,JSON不会支持二进制数据。但是,使用Google搜索可以告诉我一些名为base 64的东西(我对这一切都很陌生,所以让我承认,我是一个noob)。使用谷歌云数据存储和AJAX(斑点)-python

这是处理这个问题的唯一方法还是有其他更好的方法。

回答

1

这个线程表明,如果你只是创建一个图像元素,设置它的SRC,并将其添加到使用Javascript的网页时,浏览器将使得对图像的HTTP请求的护理:

http://bytes.com/topic/javascript/answers/472046-using-ajax-xmlhttprequest-load-images

如果你确实想用'纯粹'的AJAX来做,那么base64可能是最好的:它是一种将二进制数据(如图像)编码为文本的方式,所以你可以在json中以长字符串的形式发送它。

0

这就是我如何做到的,它在烧瓶中,但仍然是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 

希望帮助