If your application supports user-uploaded files (such as media uploads), you’ll need a storage solution separate from the application’s local filesystem. Sevalla’s object storage is ideal for securely storing and serving these files.Documentation Index
Fetch the complete documentation index at: https://docs.sevalla.com/llms.txt
Use this file to discover all available pages before exploring further.
Configuration
Start by creating an object storage on Sevalla. Settings contains all the values needed for your storages settings. This example requires the following environment variables:BUCKET_ENDPOINTBUCKET_SECRET_KEYBUCKET_ACCESS_KEYBUCKET_NAME
config.py.
Install
To upload files from FastAPI, installboto3. Sevalla’s object storage is S3-compatible, allowing the S3 client in boto3 to be used for interfacing with the object store on Sevalla.
Example
Create a client with a dependency function
Before you can upload or read files in your bucket, you need to create an S3 client. This client is used for all S3-related methods. For this example, a function is added todependencies.py and used inside any route that requires the boto3 client.
Upload a file
One method you can use to upload files is to take a file object (with a.read() method) and pass it to the upload_fileobj method. This adds it to the provided bucket with the supplied filename. This file object can come from using the UploadFile type.
List files
Thelist_objects_v2 method returns all the files in the supplied bucket.
If your bucket is private, pre-signed URLs can be created to grant access to a file for a limited period.