Attachment

class flask_attachments.Attachment[source]

Bases: object

Represents a file on the filesystem or stored in the attachment database

Attributes Summary

cached_at

When this file was written to disk

cached_filepath

The path to the file in the cache (on disk)

compressed_size

Content length in compressed form, uses the length of the contents in the database.

compression

The compression algorithm used

content_length

The length of the file in bytes, uncompressed

content_type

The MIME type of the file

contents

The compressed file contents

created

When this attachment was created (in the database)

digest

The hash digest of the file

digest_algorithm

The hash digest algorithm used

download_link

Url for downloading the file

etag

The entity tag which will uniquely correspond to this file

extension

The presumed extension for this file

filename

The name used for display and download of the attachment

id

Primary key (a UUID)

link

Url for serving the file

mimetype

The MIME type for this file, possibly inferred

size

Content length, but prefers the size of the file on disk if available

updated

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

cached_at[source]

When this file was written to disk

cached_filepath[source]

The path to the file in the cache (on disk)

compressed_size[source]

Content length in compressed form, uses the length of the contents in the database.

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 0x7fb7edeba470; 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

Url for downloading the file

etag[source]

The entity tag which will uniquely correspond to this file

extension[source]

The presumed extension for this file

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)

Url for serving the file

mimetype[source]

The MIME type for this file, possibly inferred

size[source]

Content length, but prefers the size of the file on disk if available

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

send(as_download: bool = False) Response[source]

Send this attachment as a file to the client

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

warm() None[source]

Ensure that the file exists in the cache.