_mediadb.py - ZMS Media Data Management
The mediadb module provides functionality for managing binary assets (files, images, blobs) in a ZMS instance. It handles storage, retrieval, and organization of uploaded files in a filesystem-based repository.
Key Features:
- Store and retrieve binary files (blobs) from disk
- Organize files in flat or hierarchical directory structures
- Track file references across ZMS objects and recordsets
- Migrate between different directory structures
- Identify and manage orphaned files
- Serve files as HTTP streaming responses
- Validate file integrity and references
License: GNU General Public License v2 or later, Organization: ZMS Publishing
| Class | |
Persistent Zope object that stores uploaded binary assets in a flat or hierarchical filesystem. |
| Function | container |
Return True for containers whose meta_type is 'ZMS' (used by addable object filter). |
| Function | get |
Return a flat list of mediadb filenames referenced inside an attribute value. |
| Function | manage_add |
Initialize a new MediaDb instance at the specified filesystem location and recursively attach all existing blob attributes from the object tree. |
| Function | manage_del |
Detach the mediadb from this object and remove the acl_mediadb child. The method calls recurse_delMediaDb to restore all blob data back into the ZODB, then deletes the mediadb object itself. CAVE: Restoring the blob-files back into the ZODB can massively enlarge it's size. |
| Function | manage_pack |
Scan the mediadb and move all orphaned files (not referenced by any ZMS object) to a temporary folder for cleanup or archival. |
| Function | manage_structure |
Reorganise mediadb files into the requested directory structure. The method moves all files into their new target location as computed by mediadb.targetFile(), which may involve creating intermediate directories for hierarchical structures... |
| Function | recurse_add |
Recursively attach all blob attributes of the object tree to the given mediadb. |
| Function | recurse_del |
Recursively detach blobs from the mediadb and restore their data back into ZODB. The method traverses the object tree and for each blob attribute found, it retrieves the file from the mediadb using the stored filename reference, restores the blob's data attribute with the file content, and removes the mediadb reference... |
Initialize a new MediaDb instance at the specified filesystem location and recursively attach all existing blob attributes from the object tree.
| Parameters | |
| self:object | ZMS object to attach the mediadb to. |
| location:str | Filesystem path where the mediadb should store its files. |
| REQUEST:HTTPRequest | Optional HTTP request object (not used). |
| RESPONSE:HTTPResponse | Optional HTTP response object for redirection after creation. |
Detach the mediadb from this object and remove the acl_mediadb child. The method calls recurse_delMediaDb to restore all blob data back into the ZODB, then deletes the mediadb object itself. CAVE: Restoring the blob-files back into the ZODB can massively enlarge it's size.
Scan the mediadb and move all orphaned files (not referenced by any ZMS object) to a temporary folder for cleanup or archival.
The method traverses the entire mediadb directory structure and identifies files that are not referenced by any blob attribute in the ZMS object tree. It moves these orphaned files to a temporary folder for manual review and cleanup. The method returns a message summarizing the number of orphaned files found and their new location.
Reorganise mediadb files into the requested directory structure. The method moves all files into their new target location as computed by mediadb.targetFile(), which may involve creating intermediate directories for hierarchical structures. The method also updates the mediadb structure property to ensure future uploads are stored in the correct location.
| Parameters | |
| self | Undocumented |
| structure:int | Desired directory nesting depth (0 = flat). |
| REQUEST | Undocumented |
| RESPONSE | Undocumented |
| Returns | |
| str | Message summarizing the restructuring outcome. |
Recursively detach blobs from the mediadb and restore their data back into ZODB. The method traverses the object tree and for each blob attribute found, it retrieves the file from the mediadb using the stored filename reference, restores the blob's data attribute with the file content, and removes the mediadb reference. The method also processes recordsets by iterating through their list attributes and applying the same logic to any blob values found within the records. Finally, the method recurses into child objects to ensure all blobs in the tree are processed. CAVE: Restoring the blob-files back into the ZODB can massively enlarge it's size.
| Parameters | |
| self:object | Root object to start traversal from. |
| mediadb:MediaDb | MediaDb instance to retrieve files from. |