Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42760

Delete entire blob information through BlobInfo (blob overwrite purpose)

I realize my entire blob information, is not being deleted properly, if I try to delete it through BlobInfo. (I want to perform blob overwrite) My code is as follow :

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()

However, after I had write the blob several time, based on same human, here is how my database looks like. I had uploaded for 3 times. I am only expecting to observe only one row. However, I realize there are 3 rows in __BlobFileIndex__. Human and __BlobInfo__ just look fine.

enter image description here enter image description here enter image description here

How can I perform proper delete based on BlobInfo?

Upvotes: 1

Views: 878

Answers (2)

Dave W. Smith
Dave W. Smith

Reputation: 24966

You cannot perform a blob overwrite. Once finalized, a blob is immutable until deleted.

Test that to convince yourself.

Upvotes: 2

Jim Jose
Jim Jose

Reputation: 1319

Try,

from google.appengine.ext import blobstore
blobstore.delete( '<blobstore_key>' )

Upvotes: 0

Related Questions