file.attachments

Attributes

IMAGE_MAX_SIZE

IMAGE_QUALITY

CHECKSUM_FUNCTION

Classes

_ImageSaveOptionalParams

dict() -> new empty dictionary

ProcessedUploadedFile

Simple depot.fields.interfaces.DepotFileInfo implementation that stores files.

Functions

get_svg_size_or_default(→ tuple[str, str])

strip_exif_and_store_image_size(→ IO[bytes] | None)

resize_image(→ IO[bytes])

Resize an image so that neither dimension exceeds max_size.

store_checksum(→ None)

sanitize_svg_images(→ IO[bytes])

store_extract_and_pages(→ 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(content, depot_name=None)[source]

Bases: depot.fields.upload.UploadedFile

Simple depot.fields.interfaces.DepotFileInfo implementation that stores files.

Takes a file as content and uploads it to the depot while saving around most file information. Pay attention that if the file gets replaced through depot manually the UploadedFile will continue to have the old data.

Also provides support for encoding/decoding using JSON for storage inside databases as a plain string.

Default attributes provided for all UploadedFile include:
  • filename - This is the name of the uploaded file

  • file_id - This is the ID of the uploaded file

  • path - This is a depot_name/file_id path which can

    be used with DepotManager.get_file() to retrieve the file

  • content_type - This is the content type of the uploaded file

  • uploaded_at - This is the upload date in YYYY-MM-DD HH:MM:SS format

  • url - Public url of the uploaded file

  • file - The depot.io.interfaces.StoredFile instance of the stored file

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

Standard implementation of DepotFileInfo.process_content()

This is the standard depot implementation of files upload, it will store the file on the default depot and will provide the standard attributes.

Subclasses will need to call this method to ensure the standard set of attributes is provided.