sams.storage.providers.mongo – MongoGridFS Storage Provider

MongoDB GridFS Storage Provider

This provider is enabled by default in the STORAGE_PROVIDERS config. If you need to override this default, make sure to include MongoGridFSProvider. For example:

STORAGE_PROVIDERS = [
    'sams.storage.providers.mongo.MongoGridFSProvider'
]

This will then allow destinations to be configured for Sets to use. For example:

STORAGE_DESTINATION_1 = 'MongoGridFS,Default,mongodb://localhost/sams'
class GridfsFileWrapper(gridfs_file: gridfs.grid_file.GridOut)

SuperdeskFile implementation for GridFS files

class MongoGridFSProvider(config_string: str)

Provides storage to/from MongoDB GridFS

Variables
  • _client (pymongo.mongo_client.MongoClient) – A client connected to a MongoDB Database

  • _fs (gridfs.GridFS) – A client connected to a MongoDB GridFS Collection

  • type_name (str) – The type name used to identify this provider - MongoGridFS

fs()gridfs.GridFS

Returns the underlying GridFS client handle

Returns

A GridFS client to the configured database/collection

Return type

gridfs.GridFS

exists(media_id: Union[bson.objectid.ObjectId, str])bool

Checks if a file exists in the storage destination

Parameters

media_id (bson.objectid.ObjectId) – The ID of the asset

Returns

True if a matching file exists, False otherwise

Return type

bool

put(content: Union[BinaryIO, bytes], filename: str, mimetype: Optional[str] = None)str

Upload a file to the storage destination

content must be an instance of bytes or a file-like object providing a read() method.

Parameters
  • content (bytes) – The data to be uploaded

  • filename (str) – The filename

  • mimetype (str) – The mimetype of the content (not used here)

Returns

The "id" of the created file

Return type

str

get(media_id: Union[bson.objectid.ObjectId, str])sams.storage.providers.mongo.GridfsFileWrapper

Get an asset from the storage

Parameters

media_id (bson.objectid.ObjectId) – The ID of the asset

Returns

A file-like object providing a read() method

Return type

io.BytesIO

delete(media_id: Union[bson.objectid.ObjectId, str])

Delete as asset from the storage

Parameters

media_id (bson.objectid.ObjectId) – The ID of the asset

drop()

Deletes all assets from the storage