Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion backend/chainlit/data/storage_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AzureStorageClient(BaseStorageClient):
"""
Class to enable Azure Data Lake Storage (ADLS) Gen2

parms:
params:
account_url: "https://<your_account>.dfs.core.windows.net"
credential: Access credential (AzureKeyCredential)
sas_token: Optionally include SAS token to append to urls
Expand Down Expand Up @@ -56,3 +56,32 @@ async def upload_file(self, object_key: str, data: Union[bytes, str], mime: str
except Exception as e:
logger.warn(f"S3StorageClient, upload_file error: {e}")
return {}

class MinioStorageClient(BaseStorageClient):
"""
Class to enable MinIO storage provider

params:
bucket: Bucket name, should be set with public access
endpoint_url: MinIO server endpoint, defaults to "http://localhost:9000"
aws_access_key_id: Default is "minioadmin"
aws_secret_access_key: Default is "minioadmin"
verify_ssl: Set to True only if not using HTTP or HTTPS with self-signed SSL certificates
"""
def __init__(self, bucket: str, endpoint_url: str = 'http://localhost:9000', aws_access_key_id: str = 'minioadmin', aws_secret_access_key: str = 'minioadmin', verify_ssl: bool = False):
try:
self.bucket = bucket
self.endpoint_url = endpoint_url
self.client = boto3.client("s3", endpoint_url=self.endpoint_url, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, verify=verify_ssl)
logger.info("MinioStorageClient initialized")
except Exception as e:
logger.warn(f"MinioStorageClient initialization error: {e}")

async def upload_file(self, object_key: str, data: Union[bytes, str], mime: str = 'application/octet-stream', overwrite: bool = True) -> Dict[str, Any]:
try:
self.client.put_object(Bucket=self.bucket, Key=object_key, Body=data, ContentType=mime)
url = f"{self.endpoint_url}/{self.bucket}/{object_key}"
return {"object_key": object_key, "url": url}
except Exception as e:
logger.warn(f"MinioStorageClient, upload_file error: {e}")
return {}