Hello. Consider the situation. We have a model with photo = ProcessedImageField(processors=[ResizeToFit(100, 100)]) and dynamic upload_to arg where path is calculated as md5 for the uploaded image (quite typical behaviour).
The problem is that md5 hash that is calculated is using instance.photo but it holds original uploaded image but not the one that was passed through processors.
Temp fix below kinda works.
class PatchedProcessedImageFieldFile(ImageFieldFile):
def save(self, name, content, save=True):
filename, ext = os.path.splitext(name)
spec = self.field.get_spec(source=content)
ext = suggest_extension(name, spec.format)
new_name = '%s%s' % (filename, ext)
content = generate(spec)
# PATCH: set generated file so that upload_to could use it
# (`content` is File object)
content.name = new_name
setattr(self.instance, self.field.name, content)
return super(PatchedProcessedImageFieldFile, self).save(new_name, content, save)
class PatchedProcessedImageField(ProcessedImageField):
attr_class = PatchedProcessedImageFieldFile
Hello. Consider the situation. We have a model with
photo = ProcessedImageField(processors=[ResizeToFit(100, 100)])
and dynamicupload_to
arg where path is calculated as md5 for the uploaded image (quite typical behaviour).The problem is that md5 hash that is calculated is using
instance.photo
but it holds original uploaded image but not the one that was passed through processors.Temp fix below kinda works.
May be it should be added to the master branch?