Skip to content

Instantly share code, notes, and snippets.

@Alir3z4
Alir3z4 / utils.py
Created August 9, 2016 06:19
Create a hash of a file on upload time and save it for Django FileField/ImageField
def hash_file(file, block_size=65536):
hasher = hashlib.md5()
for buf in iter(partial(file.read, block_size), b''):
hasher.update(buf)
return hasher.hexdigest()
def upload_to(instance, filename):
"""