sams_client.endpoints.images
– Images Endpoint¶
A set a collection of Assets. It is used as a way to organise and restrict access to the Assets it holds.
All access to the binary or metadata of assets will go through this service. There must be at least one Set configured in the system.
A single Set can be designated as the default Set. When access is requested to an asset without a set being provided, the default set will be used.
Usage¶
The Set service instance can be found under sams.sets.service
and used all:
from sams_client import SamsClient, IAsset, IAssetTag
client = SamsClient()
# Load the image file
with open("example_image.png", "rb") as image_file:
asset_binary = image_file.read()
set_id = client.sets.search().json()["_items"][0]["_id"]
# Upload a new Image Asset
response = client.assets.create(
docs=IAsset(
set_id=set_id,
filename="example_image.png",
name="test image renditions",
description="example image to test renditions",
tags=[
IAssetTag(code="test", name="test"),
IAssetTag(code="rendition", name="rendition")
]
),
files={"binary": asset_binary},
external_user_id="test_user_id"
)
new_asset = response.json()
# Generate a rendition
client.images.generate_rendition(
new_asset["_id"],
width=640,
height=640,
keep_proportions=True
)
# Download the newly created rendition
image_rendition = client.images.download(
new_asset["_id"],
width=640,
height=640,
keep_proportions=True
)
-
class
SamsImagesEndpoint
(client)¶ Helper class for Image Assets
-
download
(item_id: Union[bson.objectid.ObjectId, str], width: Optional[int] = None, height: Optional[int] = None, keep_proportions: Optional[bool] = True, headers: Optional[Dict[str, Any]] = None, callback: Optional[Callable[[requests.models.Response], requests.models.Response]] = None) → requests.models.Response¶ Download an Image, optionally providing image dimensions
- Parameters
- Return type
- Returns
The Asset binary, optionally resized
-
generate_rendition
(item_id: Union[bson.objectid.ObjectId, str], width: Optional[int] = None, height: Optional[int] = None, keep_proportions: Optional[bool] = True, headers: Optional[Dict[str, Any]] = None, callback: Optional[Callable[[requests.models.Response], requests.models.Response]] = None) → requests.models.Response¶ Generates an Image rendition
- Parameters
- Return type
- Returns
200 status code if rendition generated successfully
-