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)

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)