mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
fix(storage): 🐛 Create S3 bucket if it doesn't exist (#7514)
Co-authored-by: 莫岳恒 <moyueheng@datagrand.com>
This commit is contained in:
parent
2c427e04be
commit
0006c6f0fd
|
@ -28,6 +28,16 @@ class S3Storage(BaseStorage):
|
||||||
region_name=app_config.get("S3_REGION"),
|
region_name=app_config.get("S3_REGION"),
|
||||||
config=Config(s3={"addressing_style": app_config.get("S3_ADDRESS_STYLE")}),
|
config=Config(s3={"addressing_style": app_config.get("S3_ADDRESS_STYLE")}),
|
||||||
)
|
)
|
||||||
|
# create bucket
|
||||||
|
try:
|
||||||
|
self.client.head_bucket(Bucket=self.bucket_name)
|
||||||
|
except ClientError as e:
|
||||||
|
# if bucket not exists, create it
|
||||||
|
if e.response["Error"]["Code"] == "404":
|
||||||
|
self.client.create_bucket(Bucket=self.bucket_name)
|
||||||
|
else:
|
||||||
|
# other error, raise exception
|
||||||
|
raise
|
||||||
|
|
||||||
def save(self, filename, data):
|
def save(self, filename, data):
|
||||||
self.client.put_object(Bucket=self.bucket_name, Key=filename, Body=data)
|
self.client.put_object(Bucket=self.bucket_name, Key=filename, Body=data)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user