# Upload files

The following function can be used to upload a file on disk to an S3 bucket

```python
import boto3

def upload_file(key, filepath, bucket):
    # upload file from disk to S3 bucket
    client = boto3.client('s3')
    client.upload_file(
        Filename=filepath,
        Bucket=bucket,
        Key=key
    )
```

When calling the function you need to pass

* `key` - the key ("filepath") you want the file to have in the S3 bucket
* `filepath` - the path on disk for the file you want to upload
* `bucket` - the name of the bucket

```python
key = 'key_name'
filepath = 'path'
bucket = 'bucket_name'

# upload file from disk to S3-bucket
upload_file(key=key, filepath=filepath, bucket=bucket)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.backtick.se/python/s3/upload-files.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
