Skip to content

Types

sqlalchemy_file.types.FileField

Bases: TypeDecorator

Provides support for storing attachments to SQLAlchemy models.

FileField can be used as a Column type to store files into the model. The actual file itself will be uploaded to a specific libcloud.storage.base.Container, and only the File information will be stored on the database as JSON.

FileField is transaction aware, so it will delete every uploaded file whenever the transaction is rolled back and will delete any old file whenever the transaction is committed.

You can save str, bytes or any python file object

Each file will be validated by provided validators before being saved into associate storage libcloud.storage.base.Container and can go through different processors before being saved in the database.

__init__(*args, upload_storage=None, validators=None, processors=None, upload_type=File, multiple=False, extra=None, headers=None, **kwargs)

Parameters: upload_storage: storage to use validators: List of validators to apply processors: List of processors to apply upload_type: File class to use, could be used to set custom File class multiple: Use this to save multiple files extra: Extra attributes (driver specific) headers: Additional request headers, such as CORS headers. For example: headers = {'Access-Control-Allow-Origin': 'http://mozilla.com'}.

sqlalchemy_file.types.ImageField

Bases: FileField

Inherits all attributes and methods from FileField, but also validates that the uploaded object is a valid image.

__init__(*args, upload_storage=None, thumbnail_size=None, image_validator=None, validators=None, processors=None, upload_type=File, multiple=False, extra=None, headers=None, **kwargs)

Parameters upload_storage: storage to use image_validator: ImageField use default image validator, Use this property to customize it. thumbnail_size: If set, a thumbnail will be generated from original image using ThumbnailGenerator validators: List of additional validators to apply processors: List of validators to apply upload_type: File class to use, could be used to set custom File class multiple: Use this to save multiple files extra: Extra attributes (driver specific).