如果我尝试通过BlobInfo删除它,我意识到我的整个blob信息没有被正确删除。 (我想执行blob覆盖)我的代码如下:
from google.appengine.ext import db
from google.appengine.ext import blobstore
class Human(db.Model):
email = db.StringProperty(required=True)
date = db.DateTimeProperty(auto_now=True)
checksum = db.IntegerProperty(required=True)
version = db.IntegerProperty(required=True)
content = blobstore.BlobReferenceProperty(required=True)
def upload(email, checksum, version, content):
# Create the file
file_name = files.blobstore.create(mime_type='application/octet-stream', _blobinfo_uploaded_filename=email)
# Open the file and write to it
with files.open(file_name, 'a') as f:
f.write(content)
# Finalize the file. Do this before attempting to read it.
files.finalize(file_name)
# Get the file's blob key
blob_key = files.blobstore.get_blob_key(file_name)
human = model.Human(key_name=email, email=email, checksum=checksum, version=version, content=blob_key)
# Remove previous blob referenced by this human.
query = model.Human.all()
query.filter('email =', email)
# q.content is blobstore.BlobReferenceProperty(required=True)
for q in query:
q.content.delete()
human.put()
然而,在我基于同一个人编写blob几次之后,这就是我的数据库的样子。我上传了3次。我只希望观察一行。但是,我意识到__BlobFileIndex__
中有3行。 Human
和__BlobInfo__
看起来很好。
如何根据BlobInfo执行正确的删除?
答案 0 :(得分:2)
您无法执行blob覆盖。完成后,blob在删除之前是不可变的。
测试一下以说服自己。
答案 1 :(得分:0)
尝试,
from google.appengine.ext import blobstore
blobstore.delete( '<blobstore_key>' )