Have you read this ?

http://docs.djangoproject.com/en/dev/howto/custom-file-storage/

haven't used any custom file storage yet but maybe using a custom file-
storage with a dummy save method when file exists is what you need.


On Sep 12, 1:43 pm, "A. Rossi" <yobliat...@gmail.com> wrote:
> I have an application where users can upload images, then the image is
> renamed to a SHA256 hash of the file's contents.
> Here is the relevant snippet of the model
>
> class ImagePost(Post):
>     def imgurl(self, filename):
>         import hashlib, os.path
>         extension = os.path.splitext(filename)
>         self.image.seek(0)
>         return "images/%s%s" % (hashlib.sha256(self.image.read
> (self.image.size)).hexdigest(), extension[1])
>
>     image = models.ImageField(upload_to=imgurl, blank=True)
>
> what I am attempting to do is, if a user uploads an image that already
> exists (i.e. the two files have the exact same SHA256 hash) I want to
> have the ImageField point to the already existing file, rather than
> save the newly uploaded one. I have tried a couple things that didn't
> work, and the default behavior when dealing with files of the same
> name is to append an extra _ to the end of the name, before the
> extension.
>
> I feel like I'm on the cusp of figuring this out, but I'm stuck. Also,
> would I put the code for this into the imgurl() function, create a
> custom storage object, in the view(s) directly?
>
> Thank you for your help.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to