To avoid breaking existing file references when migrating from one storage to another, use DepotManager.alias(alias_name, real_storage_name).
Instead of calling get() with the real storage name, always use the alias. When you want to switch the underlying storage (e.g., from local disk to GridFS), you simply update the alias to point to the new storage. The application code using the alias remains unchanged.
# Initial setup: Local storage with an alias 'avatar'
DepotManager.configure('local_avatars', {'depot.storage_path': '/var/www/lfs'})
DepotManager.alias('avatar', 'local_avatars')
# Use the alias to save files
storage = DepotManager.get('avatar')
fileid = storage.create(open('/tmp/file.png'))
# --- Later, migrate to GridFS ---
# Configure new storage
DepotManager.configure('gridfs_avatars', {
'depot.backend': 'depot.io.gridfs.GridFSStorage',
'depot.mongouri': 'mongodb://localhost/db'
})
# Update the alias to point to the new storage
DepotManager.alias('avatar', 'gridfs_avatars')
# The same code now uses GridFS automatically
storage = DepotManager.get('avatar')
fileid = storage.create(open('/tmp/file.png'))