> ## Documentation Index
> Fetch the complete documentation index at: https://intunedhq.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# upload_file_to_s3

Uploads files to AWS S3 storage with flexible configuration options.

This function accepts various file types including Playwright Download objects, binary data,
making it versatile for different upload scenarios. It automatically handles file metadata
and provides comprehensive S3 configuration options.

```python theme={null}
async def upload_file_to_s3(
    file: FileType,
    *,
    configs: S3Configs | None,
    file_name_override: str | None,
    content_type: str | None,
) -> Attachment
```

## S3 configuration fallback

The function uses a fallback system to determine S3 settings:

1. **S3Configs Parameter** - If provided, uses the explicit `S3Configs` object with your custom settings.
2. **Environment Variables** - If no configs provided, automatically reads from environment variables:
   * `AWS_ACCESS_KEY_ID` - Your AWS access key
   * `AWS_SECRET_ACCESS_KEY` - Your AWS secret key
   * `AWS_REGION` - AWS region (e.g., "us-west-1")
   * `AWS_BUCKET` - S3 bucket name
   * `AWS_ENDPOINT_URL` - Optional custom S3 endpoint
   * Check [Environment Variables & Secrets](https://docs.intunedhq.com/docs/02-features/environment-variables-secrets) to learn more about setting environment variables.
3. **Intuned Defaults** - If environment variables aren't set, falls back to Intuned's managed S3 storage. See [S3 Attachment Storage](https://docs.intunedhq.com/docs/04-integrations/s3/s3-attachment-storage) for more details.

## Examples

<CodeGroup>
  ```python Upload Downloaded File theme={null}
  from typing import TypedDict
  from playwright.async_api import Page
  from intuned_browser import download_file, upload_file_to_s3
  from intuned_browser import S3Configs
  import os
  class Params(TypedDict):
      pass
  async def automation(page: Page, params: Params, **_kwargs):
      await page.goto("https://sandbox.intuned.dev/pdfs")
      download = await download_file(
          page,
          trigger=page.locator("xpath=//tbody/tr[1]//*[name()='svg']")
      )
      # Set your environment variables for the AWS credentials.
      # Check https://docs.intunedhq.com/docs/02-features/environment-variables-secrets to learn more about setting environment variables.
      uploaded_file = await upload_file_to_s3(
          file=download,
          configs=S3Configs(
              bucket_name=os.environ['AWS_BUCKET'],
              region=os.environ['AWS_REGION'],
              access_key=os.environ['AWS_ACCESS_KEY_ID'],
              secret_key=os.environ['AWS_SECRET_ACCESS_KEY']
          ),
          file_name_override='reports/monthly-report.pdf'
      )
      print(f"File uploaded: {uploaded_file.suggested_file_name}")
  ```

  ```python Upload Binary Data theme={null}
  from typing import TypedDict
  from playwright.async_api import Page
  from intuned_browser import upload_file_to_s3
  class Params(TypedDict):
      pass
  async def automation(page: Page, params: Params, **_kwargs):
      file_buffer = b'Hello World'
      uploaded_file = await upload_file_to_s3(
          file=file_buffer,
          file_name_override='data/text-file.txt',
          content_type='text/plain'
      )
      # Generate a temporary download URL
      download_url = await uploaded_file.get_signed_url()
      print(f"Download URL: {download_url}")
      return {
          'download_url': download_url
      }
  ```
</CodeGroup>

## Arguments

<ResponseField name="file" type="FileType" required>
  The file to upload. See [FileType](../type-references/FileType) for supported types.
</ResponseField>

<ResponseField name="configs" type="S3Configs">
  Optional [S3Configs](../type-references/S3Configs) for customizing the S3 upload. If not provided, uses environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`, `AWS_ENDPOINT_URL`, `AWS_BUCKET`). If environment variables aren't set, uses default Intuned S3 settings.
</ResponseField>

<ResponseField name="file_name_override" type="str">
  Optional custom filename for the uploaded file. If not provided, uses the original filename or generates a unique name.
</ResponseField>

<ResponseField name="content_type" type="str">
  Optional MIME type for the uploaded file (e.g., "application/pdf", "image/png"). If None, uses the original content type.
</ResponseField>

## Returns: `Attachment`

An [Attachment](../type-references/Attachment) object with file metadata and utility methods
