Files
albert.collections.files.FileCollection
Bases: BaseCollection
Manage File storage and uploads in the Albert platform.
This collection is the low-level file storage mechanism behind Albert. Files
are uploaded to and downloaded from S3-backed storage using short-lived
signed URLs, and are organized by namespace (see
FileNamespace). Files are the underlying
storage for AttachmentCollection;
to attach a file to an entity, upload it here and then create an attachment
whose key matches the stored file name. The upload_and_attach_*
helpers on the attachment collection combine both steps.
This collection is accessed as client.files.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base API route for file requests. |
Methods:
| Name | Description |
|---|---|
get_by_name |
Get stored file metadata by name and namespace. |
get_signed_download_url |
Get a temporary signed URL to download a file. |
get_signed_upload_url |
Get a temporary signed URL to upload a file. |
sign_and_upload_file |
Sign and upload a file in one step. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Source code in src/albert/collections/files.py
get_by_name
get_by_name(
*,
name: str,
namespace: FileNamespace,
generic: bool = False,
) -> FileInfo
Get stored file metadata by name and namespace.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name (storage key) of the file. |
required |
namespace
|
FileNamespace
|
The namespace the file is stored in (e.g. |
required |
generic
|
bool
|
Include generic Albert-managed files in addition to the tenant's own files. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
FileInfo
|
Metadata for the matching file. |
Source code in src/albert/collections/files.py
get_signed_download_url
get_signed_download_url(
*,
name: str,
namespace: FileNamespace,
version_id: str | None = None,
generic: bool = False,
category: FileCategory | None = None,
) -> str
Get a temporary signed URL for downloading a file.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name (storage key) of the file. |
required |
namespace
|
FileNamespace
|
The namespace the file is stored in (e.g. |
required |
version_id
|
str | None
|
A specific file version to download. Defaults to None (latest). |
None
|
generic
|
bool
|
Include generic Albert-managed files in addition to the tenant's own files. Defaults to False. |
False
|
category
|
FileCategory | None
|
The file category (e.g. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A short-lived S3 signed download URL. |
Source code in src/albert/collections/files.py
get_signed_upload_url
get_signed_upload_url(
*,
name: str,
namespace: FileNamespace,
content_type: str,
generic: bool = False,
category: FileCategory | None = None,
) -> str
Get a temporary signed URL for uploading a file.
The returned URL can be used with an HTTP PUT to upload file contents
directly to storage. In most cases, prefer sign_and_upload_file,
which performs both the signing and the upload.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name (storage key) to store the file under. |
required |
namespace
|
FileNamespace
|
The namespace to store the file in (e.g. |
required |
content_type
|
str
|
The MIME type of the file (e.g. |
required |
generic
|
bool
|
Include generic Albert-managed files in addition to the tenant's own files. Defaults to False. |
False
|
category
|
FileCategory | None
|
The file category (e.g. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A short-lived S3 signed upload URL. |
Source code in src/albert/collections/files.py
sign_and_upload_file
sign_and_upload_file(
data: IO,
name: str,
namespace: FileNamespace,
content_type: str,
generic: bool = False,
category: FileCategory | None = None,
) -> None
Sign and upload a file to Albert in one step.
Requests a signed upload URL and streams the file contents to storage.
This is the primary way to store a file; the resulting stored name can
then be used as an attachment key (see
AttachmentCollection).
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
IO
|
An open, readable binary file-like object with the file contents. |
required |
name
|
str
|
The name (storage key) to store the file under. |
required |
namespace
|
FileNamespace
|
The namespace to store the file in (e.g. |
required |
content_type
|
str
|
The MIME type of the file (e.g. |
required |
generic
|
bool
|
Include generic Albert-managed files in addition to the tenant's own files. Defaults to False. |
False
|
category
|
FileCategory | None
|
The category of the file (e.g. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|