聪明的方式引用GAE中的Blob [英] Referencing Blobs in GAE the smart way

查看:124
本文介绍了聪明的方式引用GAE中的Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将网站从IIS迁移到GAE,并试图批量上传大量图片。除了那个特殊的挑战之外,我还有一个更关心我的问题。该网站的所有内容(存储在数据库中)都是这样引用图像的: $ b http://myurl.com/images/some-folder/maybe-another-folder/image-name.jpg



我在Python中创建了一个简单的处理程序来处理图像:

  class ServeBlobs(blobstore_handlers.BlobstoreDownloadHandler):
def get(self,resource):
query =where文件名='%s'%资源
blobs = blobstore.BlobInfo.gql (query).fetch(1)
self.send_blob(blob_infos [0])

('/ images /(.*)',ServeBlobs)
<$ p

 / code> 

这很好用,不需要单独的查找表。但是,我很确定hte Blob的文件名属性不能包含'/',那么我在上面的例子中如何处理文件夹(其中有很多)称为some-folder或者maybe-another-folder?



此外,在不同文件夹中的图像名称中几乎肯定存在重叠,例如

 / images / foldera / main.jpg

/images/folderb/main.jpg

有什么想法?

解决方案

您应该将上传表单指定为文件的完整路径作为附加字段,并且完全忽略上传文件名,或将其追加到提供的路径中。

然后,您应该创建一个数据存储模型,其中包含 BlobReferenceProperty 引用blob,以完整路径作为关键名称。这样,您可以通过简单的数据存储获取blob而不是更昂贵的查询,并且还可以存储任何与实体有关的信息(例如标题信息等)。

I'm migrating a site from IIS to GAE and am trying to batch upload a lot of images. Further to that particular challenge, I have one that concerns me more. All of the content for the site (stored in a DB) reference the images as such:

http://myurl.com/images/some-folder/maybe-another-folder/image-name.jpg

I have created a simple handler in Python to serve images:

class ServeBlobs(blobstore_handlers.BlobstoreDownloadHandler):    
  def get(self, resource):        
      query = "where filename='%s'" % resource        
      blobs = blobstore.BlobInfo.gql(query).fetch(1)        
      self.send_blob(blob_infos[0])

and the 'route' is as follows

('/images/(.*)', ServeBlobs)

This works great and doesn't require a separate lookup table. However, I'm pretty sure the filename property of hte Blob can't contain '/' so what do I do about the folders (of which there are many) called some-folder or maybe-another-folder in the example above?

Furthermore, there is almost certainly overlap in image names in different folders, e.g.

"/images/foldera/main.jpg"
and
"/images/folderb/main.jpg"

Any ideas?

解决方案

You should have the upload form specify a complete path to the file as an additional field, and either ignore the upload filename entirely, or append it to the provided path.

Then, you should create a Datastore model that has a BlobReferenceProperty referencing the blob, with the full path as the key name. That way, you can look up a blob via a simple datastore get instead of a more expensive query, and you can additionally store any relevant information against the entity (such as header information, etc).

这篇关于聪明的方式引用GAE中的Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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