gpt4 book ai didi

google-app-engine - Google App Engine 中的图像响应

转载 作者:太空宇宙 更新时间:2023-11-03 15:30:04 24 4
gpt4 key购买 nike

我通过以下方式将用户图像保存为 BlobProperty:

user.image = urlfetch.fetch(image_url).content

然后我使用 url 渲染该图像,例如:

/image/user_id

图像必须保存,因为当我执行 len(user.image) 时,我得到一个数以千计的数字。在本地实例上,图像呈现正常。在部署的应用程序上,我收到以下错误,当我转到图像 url 时,浏览器中没有显示任何内容:

回溯(最近调用最后):
运行中的文件“/base/python27_runtime/python27_dist/lib/python2.7/wsgiref/handlers.py”,第 86 行
self.finish_response()
文件“/base/python27_runtime/python27_dist/lib/python2.7/wsgiref/handlers.py”,第 127 行,在 finish_response 中
自写(数据)
文件“/base/python27_runtime/python27_dist/lib/python2.7/wsgiref/handlers.py”,第 202 行,写入
assert type(data) is StringType,"write() argument must be string"
AssertionError: write() 参数必须是字符串

此外,这是提供图像的处理程序:

class ImageHandler(webapp2.RequestHandler):
""" Returns image based on id. """
def get(self, *args, **kwargs):
user = db.get(
db.Key.from_path('User', models.User.get_key_name(kwargs.get('id'))))
if user.image:
self.response.headers['Content-Type'] = "image/jpeg"
self.response.out.write(user.image)
else:
self.response.out.write("No image")

为了澄清,我尝试将内容类型设置为 jpeg 和 png。在本地服务器上一切正常。任何帮助,将不胜感激。谢谢!

最佳答案

为什么不把图片写入blobstore,然后使用send_blob()机制呢?

http://code.google.com/appengine/docs/python/blobstore/overview.html#Serving_a_Blob

关于google-app-engine - Google App Engine 中的图像响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9244291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com