Search code examples
plonedexterityblobstorage

how to cleanly remove plone.app.imaging scaled blobs in a blobstorage ZEO server?


Part of this question is already solved with another stackoverflow question but it seems that it doesn't clean up everything.

The steps are:

  • create a document with an image field
  • see that the blobstorage has one file
  • open a view with a scaled version of that image
  • see that the blobstorage now has two files, the image and the scaled image
  • do, as suggested on the other question, a zeopack with 0 days
  • see that there is still one blob on blobstorage, the scaled image

So the question is: how can one remove also this scaled images from blobstorage?

I tried running zeopack twice without success, the scaled blob is still around.

UPDATE: as vangheem pointed out, that does not happen for Archetypes Image content types. Still, this question remains valid, as for a Dexterity-based content types that have an image field.

The scales are only removed if you remove the document, which is not my use-case, I just want to remove the image (image credits have expired and the image can not be shown anymore).


Solution

  • Found it!

    To remove the scales you actually have to remove the plone.scale annotation:

    # assume 'document' is a Dexterity-based content type that has a NamedBlobImage field 
    from zope.annotation.interfaces import IAnnotations
    annotations = IAnnotations(document)
    if 'plone.scale' in annotations:
        del annotations['plone.scale']
    if getattr(document, 'image', None) is not None and document.image is not None:
        del document.image
        document.reindexObject()