Attachment¶
- class flask_attachments.Attachment[source]¶
Bases:
objectRepresents a file on the filesystem or stored in the attachment database
Attributes Summary
When this file was written to disk
The path to the file in the cache (on disk)
When this file was written to disk
The compression algorithm used
The length of the file in bytes, uncompressed
The MIME type of the file
The compressed file contents
When this attachment was created (in the database)
The hash digest of the file
The hash digest algorithm used
Url for downloading the file
The entity tag which will uniquely correspond to this file
The presumed extension for this file
The name used for display and download of the attachment
Primary key (a UUID)
Url for serving the file
The MIME type for this file, possibly inferred
When this file was written to disk
When this attachment record was last updated
Methods Summary
data(data[, compression, digest_algorithm])Load a file from bytes into this attachment
from_file(file[, content_type, compression, ...])Create a new attachment by reading a file from disk
receive(file)Receive an uploaded file, compressing and saving it as appropritate
send([as_download])Send this attachment as a file to the client
streamed(stream[, compression, ...])Stream a file from bytes into this attachment
warm()Ensure that the file exists in the cache.
Attributes Documentation
- compression: Mapped[CompressionAlgorithm] = <sqlalchemy.orm.properties.MappedColumn object>¶
The compression algorithm used
- content_length: Mapped[int] = <sqlalchemy.orm.properties.MappedColumn object>¶
The length of the file in bytes, uncompressed
- content_type: Mapped[str] = <sqlalchemy.orm.properties.MappedColumn object>¶
The MIME type of the file
- contents: Mapped[bytes] = <MappedSQLExpression at 0x7ff4b47c2470; no key>¶
The compressed file contents
- created: Mapped[datetime] = <sqlalchemy.orm.properties.MappedColumn object>¶
When this attachment was created (in the database)
- digest: Mapped[str] = <sqlalchemy.orm.properties.MappedColumn object>¶
The hash digest of the file
- digest_algorithm: Mapped[str] = <sqlalchemy.orm.properties.MappedColumn object>¶
The hash digest algorithm used
- filename: Mapped[str] = <sqlalchemy.orm.properties.MappedColumn object>¶
The name used for display and download of the attachment
- id: Mapped[UUID] = <sqlalchemy.orm.properties.MappedColumn object>¶
Primary key (a UUID)
- updated: Mapped[datetime] = <sqlalchemy.orm.properties.MappedColumn object>¶
When this attachment record was last updated
Methods Documentation
- data(data: bytes, compression: CompressionAlgorithm | str | None = None, digest_algorithm: str | None = None) None[source]¶
Load a file from bytes into this attachment
- classmethod from_file(file: str | PathLike[str], content_type: str | None = None, compression: CompressionAlgorithm | str | None = None, digest_algorithm: str | None = None) Attachment[source]¶
Create a new attachment by reading a file from disk
- receive(file: FileStorage) None[source]¶
Receive an uploaded file, compressing and saving it as appropritate
- streamed(stream: IO[bytes], compression: CompressionAlgorithm | str | None = None, digest_algorithm: str | None = None, chunk_size: int = 16384) None[source]¶
Stream a file from bytes into this attachment