Raf
Raf

Reputation: 684

What is md5_hash property of BlobInfo object intended for?

If I call

blobsotre.BlobInfo.properties() 

the function return

set(['filename', 'creation', 'content_type', 'md5_hash', 'size'])

but if I call

a = blobstore.BlobInfo.all()
obj = a.fetch(1)[0]
print obj.md5_hash

the function raise exception

AttributeError(name) AttributeError: md5_hash

What is md5_hash property of BlobInfo object intended for? P.S. I want to check what uploaded file is not exist into Blobstore.

Upvotes: 1

Views: 616

Answers (3)

joewest
joewest

Reputation: 21

You probably have BlobInfo objects that don't have an md5_hash written including the first result returned by blobstore.BlobInfo.all()

You can check easily in your dev server's interactive console:

from google.appengine.ext import blobstore

query1 = blobstore.BlobInfo.all()
query2 = blobstore.BlobInfo.gql("WHERE md5_hash != ''")

print query1.count(), query2.count()
# for me this returns '100 85'

Upvotes: 1

Nick Johnson
Nick Johnson

Reputation: 101149

The code you show works fine for me, on shell.appspot.com:

>>> from google.appengine.ext import blobstore
>>> blobstore.BlobInfo.properties()
set(['filename', 'creation', 'content_type', 'md5_hash', 'size'])
>>> o = blobstore.BlobInfo.all().get()
>>> o.md5_hash
u'5d41402abc4b2a76b9719d911017c592'

You must be doing something different to what's in your sample code. Can you paste your exact code, and the complete stacktrace?

Upvotes: 1

Dave
Dave

Reputation: 3956

A cryptographic hash function can be used for many things:

  • to provide an integrity check value for the file/blob to detect changes
  • to provide a unique identifier for a file/blob used to refer to the contents
  • to enable fast lookup of the contents of a hash table
  • to enable fast searching for duplicate files
  • etc

The "intended" use of course depends on what application the blobstore is supporting - are you building a shopping cart, or a data cache, or a map-reduce processing application, or what?

Upvotes: 1

Related Questions