Monday, May 31, 2010

Re: Image deduplication and upload_to

Thanks. I have successfully made a lobotomized version I called
OverwritingStorage that extends FileStorage and overrides
get_available_name, _save and delete (and offers a hashed_path
classmethod to be used in upload_to callables)

http://djangosnippets.org/snippets/2044/

Now my problem is not being able to wrap my head around computing an
ImageField based on another ImageField (in my case, a default
thumbnail that can be edited later)

But that deserves its own thread.

On Thu, May 27, 2010 at 6:37 AM, Nuno Maltez <nuno.lists@gmail.com> wrote:
> Hi,
>
> I think it's designed to do that. See the behaviour of the
> save/get_available_name methods on core/files/storage.py (in the
> django source). Maybe you can write your own storage that overrides
> this (never tried it, but should work).
>
> Nuno
>
> 2010/5/26 Ricardo Bánffy <rbanffy@gmail.com>:
>> Hi folks.
>>
>> I want to prevent the duplication of uploaded images. For that, I am
>> using the upload_to property of ImageField set to a callable that
>> computes the md5 hash of the uploaded file data and returns a file
>> name. This should work _but_ when I save the model, the filename I
>> gave back in the function is getting a "_1", "_2" and so on suffix to
>> prevent my efforts at deduplication.
>>
>> http://dpaste.com/199576/
>>
>> Anyone has had a similar problem?
>>
>> I understand I'll have to take care of other problems too, like
>> preventing the deletion of files that are referenced by more than one
>> ImageFile and could do something to prevent the actual overwriting of
>> the same data on the same file as before, but that's a start.
>>
>>
>> --
>> Ricardo Bánffy
>> http://www.dieblinkenlights.com
>> http://twitter.com/rbanffy
>>
>> --
>> 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+unsubscribe@googlegroups.com.
>> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>>
>>
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>

--
Ricardo Bánffy
http://www.dieblinkenlights.com
http://twitter.com/rbanffy

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment