gforcada
gforcada

Reputation: 2558

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:

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).

Upvotes: 1

Views: 470

Answers (2)

gforcada
gforcada

Reputation: 2558

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()

Upvotes: 2

vangheem
vangheem

Reputation: 3293

Deleting the content item should delete its scales also.

I just testing in plone 4.2.4. Here were my steps:

  1. delete existing blobstorage and filestorage
  2. start up plone
  3. create new site
  4. add image, see that 2 blobstorage files are created. One the original, another the one scale that has been created so far
  5. delete the image, both files are still in blobstorage for undo support
  6. pack the database to 0 days, both files are now removed from blobstorage

So everything seems to be working correctly.

In your post you mention that you're creating a document. If you means News Item, those images aren't stored in blobstorage.

Now, if you have a custom content type where you have an image field and you're just trying to delete the image field and the scales generated from that field, but not delete the entire type, you'll need to delete the scales manually. I think it'll be something like this:

del doc.__blob_scales['image']['preview']

Upvotes: 2

Related Questions