Sorl-Thumbnail in Django. Is it possible to set Two or more storage profile dependent of model?

333 views Asked by At

I work on my first bigger project. I use AWS S3 to storage my static and media files.

I found way to set storage depends on the model. For public images and private images in messages. The "source" files are uploaded with right acl settings "public-read" for public images and "private" for files in message system. But when I use sorl-thumbnails all pics generated by sorl are public. I need secure private pics and don't want use public acl for private files.

Do you know a workaround for this problem?

What comes to my mind:

  • use another thumbs app for private files and change storage for example in backend or config.
  • change name convention in backend sorl to expand the number of characters in filename. It is not what I exactly want but much harder to find files by names.
1

There are 1 answers

0
takelbery On

I come back to my project and try fix this issue. I must secure private files in messages for my future users.

So. I looked at how sorl is work in sources and I found solution.

In the file sorl/base.py I found this:

on def get_thumbnails

thumbnail = ImageFile(name, default.storage)

and I change it to:

if hasattr(file_, 'storage'):
    thumbnail = ImageFile(name, file_.storage)
else:
    thumbnail = ImageFile(name, default.storage)

And this is it. Now if I define storage in ImageFields in my model sorl will use the same storage for thumbnails.

Now I will start work to put this change to own Backend for sorl :)

Best Regards