file.attachments

Attributes

IMAGE_MAX_SIZE

IMAGE_QUALITY

CHECKSUM_FUNCTION

Classes

_ImageSaveOptionalParams

dict() -> new empty dictionary

ProcessedUploadedFile

Functions

get_svg_size_or_default(content) → tuple[str, str]

strip_exif_and_store_image_size(file, content, ...) → IO[bytes] | None

resize_image(content[, max_size]) → IO[bytes]

Resize an image so that neither dimension exceeds max_size.

store_checksum(file, content, content_type) → None

sanitize_svg_images(file, content, content_type) → IO[bytes]

store_extract_and_pages(file, content, content_type) → None

Module Contents

class file.attachments._ImageSaveOptionalParams[source]

Bases: TypedDict

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

exif: NotRequired[PIL.Image.Exif][source]
file.attachments.IMAGE_MAX_SIZE = 4096[source]
file.attachments.IMAGE_QUALITY = 85[source]
file.attachments.CHECKSUM_FUNCTION = 'md5'[source]
file.attachments.get_svg_size_or_default(content: IO[bytes]) → tuple[str, str][source]
file.attachments.strip_exif_and_store_image_size(file: ProcessedUploadedFile, content: IO[bytes], content_type: str | None) → IO[bytes] | None[source]
file.attachments.resize_image(content: IO[bytes], max_size: int = IMAGE_MAX_SIZE) → IO[bytes][source]

Resize an image so that neither dimension exceeds max_size.

When a resize is performed the EXIF orientation is baked in and the EXIF block is stripped in the same pass, so the depot processor’s EXIF-stripping step becomes a no-op and the image is only encoded once.

Non-image streams and images that are already within the limit are returned unchanged (seeked to 0). Large images are resampled into a new SpooledTemporaryFile.

file.attachments.store_checksum(file: ProcessedUploadedFile, content: IO[bytes], content_type: str | None) → None[source]
file.attachments.sanitize_svg_images(file: ProcessedUploadedFile, content: IO[bytes], content_type: str | None) → IO[bytes][source]
file.attachments.store_extract_and_pages(file: ProcessedUploadedFile, content: IO[bytes], content_type: str | None) → None[source]
class file.attachments.ProcessedUploadedFile[source]

Bases: depot.fields.upload.UploadedFile

processors[source]
process_content(content: depot.io.interfaces._FileContent, filename: str | None = None, content_type: str | None = None) → None[source]