LA_
LA_

Reputation: 20419

How to verify if Blobstore Files record already exists?

Looks like get_file_name(blob_key) can be used in accordance with Blobstore Files API Functions doc. But this is in case I know blob_key (actually, I know it, but this is additional request to datastore).

I would like to verify that the same file is not added to Blobstore second time. Filename is unique. So, can I check presence of record by file name?

Upvotes: 0

Views: 525

Answers (1)

voscausa
voscausa

Reputation: 11706

No you cannot check for the filename. Every time you create or opload a file with the same name to the blobstore it will be added with te same name, but a new blob_key.

Here is some code to delete the old versions of the blob

..... code to create a new blob with filename = name
files.finalize(f_name)                                   # finalize the new blob                        
blob_key = files.blobstore.get_blob_key(f_name)          # get the blob_key of the newly saved blob
blobs = blobstore.BlobInfo.gql("WHERE filename = '%s'" %(name))                            
for blob in blobs :
    if blob.key() != blob_key : blob.delete()            # delete old versions of the blob     

Upvotes: 1

Related Questions