file.attachments
Attributes
Classes
dict() -> new empty dictionary |
|
Simple |
Functions
|
|
|
|
|
Resize an image so that neither dimension exceeds max_size. |
|
|
|
|
|
Module Contents
- class file.attachments._ImageSaveOptionalParams[source]
Bases:
TypedDictdict() -> 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)
- 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.UploadedFileSimple
depot.fields.interfaces.DepotFileInfoimplementation 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
UploadedFilewill 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
UploadedFileinclude: 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.StoredFileinstance of the stored file
- 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.
- Default attributes provided for all