django-imagekit
django-imagekit copied to clipboard
Configurable Celery serialzier
Pickle is considered as an unsafe serializer, so support for e.g. application/json
would be great.
https://github.com/matthewwithanm/django-imagekit/blob/3317273401d65b1d2c70c635e22132998f957290/imagekit/cachefiles/backends.py#L147
I'll be very glad if someone is willing to provide a PR with this functionality.
Ran into this, we only accept json as serializer, for obvious reasons.
The problem is that the file object that is passed around either is too complex in parameters to correctly serialize and deserialize.
If I could somehow get the ContentType of the model, the ID and the field_name then I could reconstruct it and simply call _generate() on the field.
OK, did some searching and can get the model through: file.generator.source.instance
The problem is that I can't find the attribute name that needs to be generated:
I have a logo image field and multiple image specs that generate different thumbnails from that.
For now I can use celery-once to create a task only once per model, and then use the generator_registry.get_ids()
to find out which generators there are for a given model get the model and generate the images one by one.
It works, but it's far from ideal.
Why can't we pass filepath to celery/any async shedule_generation
method instead of file argument and then find the file by the filepath variable?
Because you need more information on how to thumbnail the image, the file itself it not enough.
@hvdklauw i suggest just replacing file with filepath and when file itself is needed, find it by name. Nothing else would change
for example u can find file by name before that https://github.com/matthewwithanm/django-imagekit/blob/f15c7c105823712378d3ad2dafc6664969c627c1/imagekit/cachefiles/backends.py#L96
The file there is an ImageCacheFile, which has all the parameters on how to generate a thumbnail, the original file alone is not enough because you might use the original to generate 3 or 4 different thumbnails, so which one are you generating?
So no solutions?
I totally wrote my own solution that just starts a task with the app label and model name (from ContentTypes) and an id, then the task loads it and just generates all the thumbnails.