Question

I'm trying to set up permission checking to static files uploaded by users. To do this, I use the path requested to get the media object which represents the file. I also use sorl-thumbnail library to make thumbnails. I use get_thumbnail() function to get the cached thumbnail from an url of the original uploaded picture. Is there any way of doing the inverse operation? from a cached image url, can i have the original url? something like:

picture = Image.objects.get(url=get_original('/cached/url/of/the/thumbnail/image'))
Was it helpful?

Solution

There is no default way to do this. Sorl thumbnail generates the path for the new thumbnail by creating a hash of the original file name along with the options you have specified so there is no easy way to reverse that operation. You could create a DB table the maps the original image file to your current thumbnail and keeps it up to date everytime the dimensions etc. change.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top