Python, get base64-encoded MD5 hash of an image object -
i need base64-encoded md5 hash of object, object image stored file, fname.
i've tried this:
def get_md5(fname): hash = hashlib.md5() open(fname) f: chunk in iter(lambda: f.read(4096), ""): hash.update(chunk) return hash.hexdigest().encode('base64').strip()
however, don't think right because returns string many characters. understanding needs 24 characters long. get
njjim2rlowmzotyxymm3mdi5y2q1nzdjotq5ywrlytq=
i've tried few other similar ways well, example, 1 not chunk loop thing. return same string.
(my later actions need base64-encoded md5 hash fail, , i'm thinking why.)
i able make work using digest() instead of hexdigest(). last line becomes:
return hash.digest().encode('base64').strip()
the result 24 characters long, , accepted google cloud storage transfer, required base64-encoded md5 hash.
Comments
Post a Comment