[Solved]-Pointers on using celery with sorl-thumbnails with remote storages?


I think what you want to do is set THUMBNAIL_BACKEND to a custom class that overrides the _create_thumbnail method. Instead of generating the thumbnail in that function, kick of a celery task that calls _create_thumbnail with the same arguments as given to the function. The thumbnail won’t be available during the request, but it will get generated in the background.


As I understand Sorl works correctly with the S3 storage but it’s very slow.

I believe that you know what image sizes do you need.

You should launch the celery task after the image was uploaded. In task you call to
sorl.thumbnail.default.backend.get_thumbnail(file, geometry_string, **options)

Sorl will generate a thumbnail and upload it to S3. Next time you request an image from template it’s already cached and served directly from Amazon’s servers

a clean way to handle a placeholder thumbnail image while the image is being processed.

For this you will need to override the Sorl backend. Add new argument to get_thumbnail function, e.g. generate=False. When you will call this function from celery pass generate=True

And in function change it’s logic, so if thumb is not present and generate is True you work just like the standard backend, but if generate is false you return your placeholder image with text like “We process your image now, come back later” and do not call backend._create_thumbnail. You can launch a task in this case, if you think that thumbnail can be accidentally deleted.

I hope this helps



You can use Sorlery. It combines sorl and celery to create thumbnails via workers. It’s very careful not to do any filesystem access outside of the worker thread.

The thumbnail returned immediately (before the worker has had a chance) can be controlled by setting your THUMBNAIL_DUMMY_SOURCE to an appropriate placeholder.

The job is created the first time the thumbnail is requested, subsequent requests are served the dummy image until the worker thread completes.


Leave a comment