Skip to content

attachments

Bases: BaseAttachments

Source code in airia/client/attachments/async_attachments.py
def __init__(self, request_handler: AsyncRequestHandler):
    super().__init__(request_handler)

get_file_url(file_id, correlation_id=None) async

Get a refreshed signed URL for an existing attachment.

This method retrieves a new time-limited signed URL for accessing an attachment that was previously uploaded. Useful when the original signed URL has expired or is about to expire.

Parameters:

Name Type Description Default
file_id str

The unique identifier of the attachment

required
correlation_id Optional[str]

Optional correlation ID for request tracing. If not provided, one will be generated automatically.

None

Returns:

Name Type Description
GetFileUrlResponse GetFileUrlResponse

Response containing the attachment ID and refreshed signed URL.

Raises:

Type Description
AiriaAPIError

If the API request fails with details about the error.

ClientError

For other request-related errors.

Example
async_client = AiriaAsyncClient(api_key="your_api_key")

# First, upload a file
upload_response = await async_client.attachments.upload_file(
    file_path="example.jpg"
)
file_id = upload_response.id

# Later, get a refreshed URL for the same file
url_response = await async_client.attachments.get_file_url(
    file_id=file_id
)
print(f"Attachment ID: {url_response.id}")
print(f"Refreshed URL: {url_response.signed_url}")
Source code in airia/client/attachments/async_attachments.py
async def get_file_url(
    self,
    file_id: str,
    correlation_id: Optional[str] = None,
) -> GetFileUrlResponse:
    """
    Get a refreshed signed URL for an existing attachment.

    This method retrieves a new time-limited signed URL for accessing
    an attachment that was previously uploaded. Useful when the original
    signed URL has expired or is about to expire.

    Args:
        file_id: The unique identifier of the attachment
        correlation_id: Optional correlation ID for request tracing. If not provided,
                    one will be generated automatically.

    Returns:
        GetFileUrlResponse: Response containing the attachment ID and refreshed signed URL.

    Raises:
        AiriaAPIError: If the API request fails with details about the error.
        aiohttp.ClientError: For other request-related errors.

    Example:
        ```python
        async_client = AiriaAsyncClient(api_key="your_api_key")

        # First, upload a file
        upload_response = await async_client.attachments.upload_file(
            file_path="example.jpg"
        )
        file_id = upload_response.id

        # Later, get a refreshed URL for the same file
        url_response = await async_client.attachments.get_file_url(
            file_id=file_id
        )
        print(f"Attachment ID: {url_response.id}")
        print(f"Refreshed URL: {url_response.signed_url}")
        ```
    """
    request_data = self._pre_get_file_url(
        file_id=file_id,
        correlation_id=correlation_id,
        api_version=ApiVersion.V1.value,
    )

    resp = await self._request_handler.make_request(
        "GET", request_data, return_json=True
    )
    return GetFileUrlResponse(**resp)

upload_file(file_path, correlation_id=None) async

Upload a file and get attachment information.

Parameters:

Name Type Description Default
file_path str

Path to the file on disk

required
correlation_id Optional[str]

Optional correlation ID for request tracing. If not provided, one will be generated automatically.

None

Returns:

Name Type Description
AttachmentResponse AttachmentResponse

Response containing the attachment ID and URL.

Raises:

Type Description
AiriaAPIError

If the API request fails with details about the error.

ClientError

For other request-related errors.

Example
async_client = AiriaAsyncClient(api_key="your_api_key")

# Upload a file
response = await async_client.attachments.upload_file(
    file_path="example.jpg"
)
print(f"Uploaded attachment ID: {response.id}")
print(f"Attachment URL: {response.image_url}")
Source code in airia/client/attachments/async_attachments.py
async def upload_file(
    self,
    file_path: str,
    correlation_id: Optional[str] = None,
) -> AttachmentResponse:
    """
    Upload a file and get attachment information.

    Args:
        file_path: Path to the file on disk
        correlation_id: Optional correlation ID for request tracing. If not provided,
                    one will be generated automatically.

    Returns:
        AttachmentResponse: Response containing the attachment ID and URL.

    Raises:
        AiriaAPIError: If the API request fails with details about the error.
        aiohttp.ClientError: For other request-related errors.

    Example:
        ```python
        async_client = AiriaAsyncClient(api_key="your_api_key")

        # Upload a file
        response = await async_client.attachments.upload_file(
            file_path="example.jpg"
        )
        print(f"Uploaded attachment ID: {response.id}")
        print(f"Attachment URL: {response.image_url}")
        ```
    """
    request_data = self._pre_upload_file(
        file_path=file_path,
        correlation_id=correlation_id,
        api_version=ApiVersion.V1.value,
    )

    resp = await self._request_handler.make_request_multipart("POST", request_data)
    return AttachmentResponse(**resp)