【发布时间】:2014-07-24 19:04:39
【问题描述】:
我一直在遵循此站点上的说明 - Is it possible to find and delete orphaned blobs in the app engine blobstore? - 关于如何删除孤立的 blob,但我一直收到错误消息。
from google.appengine.ext.blobstore import BlobInfo
#Here is where I store my blobKeys
class Content(ndb.Model):
blobKey = ndb.BlobKeyProperty(required=False)
#Here is what I've been trying to follow
class Refresh(blobstore_handlers.BlobstoreUploadHandler):
def get(self):
blobs = BlobInfo.all().fetch(500)
for blob in blobs:
if not Content.all().filter("blob_ref =", blob.key()).count(1): #ERROR
blob.delete()
我不断收到错误AttributeError: type object 'Content' has no attribute 'all'
海报提到“如果您的 BlobReferenceProperty 字段被索引,那么是的,这很有可能。”可能是我使用 ndb.BlobKeyProperty 而不是 BlobReferenceProperty 的问题吗?谢谢,阅读。
更新 参考Expected BlobKey but instead I get a BlobInfo object - How to get BlobKey from BlobInfo object?查看解决方案
【问题讨论】:
-
Google 正在远离 blobstore。 Files api 已被弃用。您可以使用不允许具有相同文件名的 blob 版本的 Google 云存储。
-
谢谢 voscausa,不过我有一个问题。当谷歌说“文件 api 已被弃用”时,这是否意味着您将不再能够将图片上传到 blobstore?根据developers.google.com/appengine/docs/python/blobstore 看来
blob_info = upload_files[0]会没事的。 -
换句话说,我的代码中根本没有使用
from google.appengine.api import files -
是的,您仍然可以上传文件。如果应用程序将数据写入 blobstore,则仅需要 Files API。
标签: google-app-engine blobstore