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 

希望幫助