【问题标题】:blobkey from blobstore google apps engine python来自 blobstore 谷歌应用引擎 python 的 blobkey
【发布时间】:2012-01-19 02:41:42
【问题描述】:

如何从 blob 存储返回 blob 密钥?然后返回图像 URL?

示例代码:

class Next(webapp.RequestHandler):
    def get(self):
        userTable_name=self.request.get('userTable_name')

        data  = db.GqlQuery("SELECT * "
                                "FROM userTable "
                                "WHERE ANCESTOR IS :1 "
                                "ORDER BY date DESC LIMIT 10",
                                userTable_key(userTable_name))

        self.response.headers['Content-Type'] = 'text/plain'


        for user in data:
            blobURL = get_serving_url(user.imageblob.key(), size=None, crop=False)
            self.response.out.write(blobURL)

我正在使用 GqlQuery 返回一组 Blob(即 user.imageblob),并且我需要为每个 Blob 确定 BlobKey。据我所知,“user.imageblob.key()”不返回 blobkey...?

【问题讨论】:

  • 它返回:“ValidateString if len(value.encode('utf-8')) > max_len: UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range (128)"
  • user.imageblob.key() blobkey,尽管获取它的效率低下。请在您的问题中包含您尝试过的实际代码和完整的堆栈跟踪。
  • 也许这个回答的问题会有所帮助:stackoverflow.com/questions/3887535/…

标签: python google-app-engine blobstore


【解决方案1】:

解决了!事实证明,我很困惑“将图像作为 blob 添加到数据存储区”与将图像添加到 blob 存储区。

BlobReferenceProperty 引用上传并存储在 blobstore,而 BlobProperty 将 blob 数据直接存储在 数据存储。见:How to use get_serving_url in appengine?

因此,get_serving_url()user.imageblob.key() 错误地指向数据存储而不是 Blob 存储。

有关将图像添加到 blobstore 的示例,请参阅:http://code.google.com/appengine/docs/python/blobstore/overview.html

【讨论】:

    猜你喜欢
    • 2011-04-18
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 2013-03-28
    • 2023-03-15
    • 2011-01-11
    • 2014-07-20
    • 2011-08-21
    相关资源
    最近更新 更多