Upload Files
Set up environment
Upload a file
To upload a file using the Athena SDK, you can use the upload.upload_documents()
method. This method accepts a list of file tuples, where each tuple contains the filename, file content as a BytesIO object, and the MIME type.
Here’s an example of how to upload an Excel file:
In this example:
- We open the file and read its contents into a
BytesIO
object. - We create a tuple containing the filename, the
BytesIO
object, and the MIME type. - We call
athena.upload.upload_documents()
with a list containing our file tuple. - The function returns the result of the upload operation.
Upload multiple files
You can upload multiple files in a single request by adding more file tuples to the list:
Using with FastAPI
If you’re using FastAPI and want to upload files received from a client, you can use the UploadFile
object:
This endpoint will accept file uploads and forward them to the Athena API using the SDK.
Remember to handle exceptions and implement proper error checking in your production code.