how to remove file(blob) from blobdir after object is deleted form zodb(data.fs)

337 views Asked by At

i have uploaded file(PDF 4mb) on server it is stored in blobdir. and reference in object of MYCLASS with attribute attachment in (zodb data.fs). if i am deleting object of MYCLASS then that object is deleted but the file(PDF 4mb) on blobdir is not deleted. how to delete that blob file after object is deleted?

1

There are 1 answers

0
Martijn Pieters On BEST ANSWER

The file is part of a past ZODB revision. You'll need to pack your ZODB database to remove historical revisions.

How far back you pack your database is up to you. Once you have removed old revisions you can no longer roll back the database to those states anymore.

How you pack the ZODB depends on your setup. If you are using ZEO there is a command-line tool (zeopack) that instructs ZEO server to pack the storage for you.

You can also do it programmatically; from your Pyramid app, for example, with the db.pack() method:

import time
from pyramid_zodbconn import get_connection

db = get_connection(request).db()
db.pack(days=7)

I used the days parameter to pack the ZODB but retain history for the past week. You can also use a timestamp t (UNIX seconds since the epoch) to specify a specific point in time to which to pack, or omit either to remove all old revisions.

Once the revision that references the blob is removed, the blob file is not immediately removed; whenever you pack a backup is created in case you need to revert the operation. A future pack operation replaces the previous backup with the new backup, clearing the blobs for good.