将数据存储区实体链接到其Blobstore映像的最佳方法? [英] Best way to link datastore entity to its blobstore image?

查看:73
本文介绍了将数据存储区实体链接到其Blobstore映像的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  class contact(db.Model):
email = db.EmailProperty()
image = #Hmm。

我的联系人图片将存储在Blobstore中,并以各种尺寸显示。



因此,我应该使用 db.ReferenceProperty(BlobInfo),以便我可以通过执行以下操作:

  get_serving_url(alice.image.key,size = x)

或者我应该使用 db.StringProperty ,以便我不必为了获得密钥而进行第二次读取:

  get_serving_url(alice.image,size = x)

或者我应该使用基本URL的 db.LinkProperty ,后期修正所需的大小:

  alice.image +'= sx'






我不预见需要除键之外的任何东西,所以我认为第二个比第一个好。



虽然我不确定第三个是不是最好的,因为我不确定它是否与创建唯一URL一样高效,它可以缓存,以避免重复生成相同的缩略图 - 或者这两种情况下自动处理?

解决方案

经过一些实验,我想我可以回答我自己的问题。

好的,有点。事实证明,答案是这不是一个真正的问题开始。



虽然 get_serving_url()给人的印象是正在做某事,实际上'服务URL'只不过是提供的 BlobKey 的后期修改。



更重要的是,提供 size = x 只会追加 = sx - 没有什么特别的,或多或少有效,就这样做。最后, __ BlobInfo __ 实体种类使用 BlobKey 作为它的关键名称,所以它也很容易从另一个访问。






我决定使用,并建议任何人都有同样的困境,我的第三个选择:

  imgBlob = db。 LinkProperty()

很容易:


  • 附加任何调整大小/裁剪要求

  • 给出默认值/ make不需要重载 put()


  • Let's say I have a model for my email address book:

    class contact(db.Model):
        email = db.EmailProperty()
        image = #Hmm.
    

    My contacts' images will be stored in the Blobstore, and served at various sizes.

    So, should I use a db.ReferenceProperty(BlobInfo) such that I can serve it by doing:

    get_serving_url(alice.image.key, size=x)
    

    Or should I use a db.StringProperty so that I don't have to make the second read in order to get the key:

    get_serving_url(alice.image, size=x)
    

    Or should I use a db.LinkProperty for the base URL, post-fixing the size needed:

    alice.image+'=sx'
    


    I don't foresee needing anything other than the key, so I think the second is better than the first.

    Though I am unsure if the third is best because I am unsure whether it is as efficient as creating a unique URL, which can be cached to avoid repeatedly generating the same thumbnail - or is this handled automagically in both cases?

    解决方案

    After some experimentation, I think I can answer my own question.

    Well, sort of. It turns out that the answer is "this wasn't a real problem to begin with".

    While get_serving_url() gives the impression that something fancy is being done, actually the 'serving URL' is nothing more than a post-fixing of the supplied BlobKey.

    What's more, supplying size=x merely appends =sx - there's nothing special, more or less efficient, about doing it this way. My second and third options, really are identical.

    Finally, the __BlobInfo__ entity kind uses the BlobKey as its key name, so it is also easy to access from the other.


    I have decided to use, and would suggest to anyone with the same dilemma, my third option:

    imgBlob = db.LinkProperty()
    

    It is then easy to:

    • append any resizing/cropping requirements
    • give a default value/make required without overloading put()

    这篇关于将数据存储区实体链接到其Blobstore映像的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆