Skip to content

Commit

Permalink
feat: add MinIO as storage provider
Browse files Browse the repository at this point in the history
  • Loading branch information
azlkiniue committed Apr 30, 2024
1 parent 1da265b commit 901bee0
Showing 1 changed file with 30 additions and 1 deletion.
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 {}

0 comments on commit 901bee0

Please sign in to comment.