Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(storage): 🐛 Create S3 bucket if it doesn't exist (#7514)

Vimpas0006c6f0fdae
diff --git a/api/extensions/storage/s3_storage.py b/api/extensions/storage/s3_storage.py
index 022ce5b14a7..424d441cdcb 100644
--- a/api/extensions/storage/s3_storage.py
+++ b/api/extensions/storage/s3_storage.py
@@ -28,6 +28,16 @@ class S3Storage(BaseStorage):
region_name=app_config.get("S3_REGION"),
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):
self.client.put_object(Bucket=self.bucket_name, Key=filename, Body=data)