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.

feat: support aliyun oss auth v4 (#3886)

S96EA13cd4095756b
diff --git a/api/.env.example b/api/.env.example
index 0409eb7bcaf..30bbf331a4c 100644
--- a/api/.env.example
+++ b/api/.env.example
@@ -54,6 +54,9 @@ ALIYUN_OSS_BUCKET_NAME=your-bucket-name
ALIYUN_OSS_ACCESS_KEY=your-access-key
ALIYUN_OSS_SECRET_KEY=your-secret-key
ALIYUN_OSS_ENDPOINT=your-endpoint
+ALIYUN_OSS_AUTH_VERSION=v1
+ALIYUN_OSS_REGION=your-region
+
# Google Storage configuration
GOOGLE_STORAGE_BUCKET_NAME=yout-bucket-name
GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON=your-google-service-account-json-base64-string
diff --git a/api/config.py b/api/config.py
index dd100a479a2..d6c345c5793 100644
--- a/api/config.py
+++ b/api/config.py
@@ -215,6 +215,8 @@ class Config:
self.ALIYUN_OSS_ACCESS_KEY=get_env('ALIYUN_OSS_ACCESS_KEY')
self.ALIYUN_OSS_SECRET_KEY=get_env('ALIYUN_OSS_SECRET_KEY')
self.ALIYUN_OSS_ENDPOINT=get_env('ALIYUN_OSS_ENDPOINT')
+ self.ALIYUN_OSS_REGION=get_env('ALIYUN_OSS_REGION')
+ self.ALIYUN_OSS_AUTH_VERSION=get_env('ALIYUN_OSS_AUTH_VERSION')
self.GOOGLE_STORAGE_BUCKET_NAME = get_env('GOOGLE_STORAGE_BUCKET_NAME')
self.GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64 = get_env('GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64')
diff --git a/api/extensions/storage/aliyun_storage.py b/api/extensions/storage/aliyun_storage.py
index e09ed607958..b81a8691f15 100644
--- a/api/extensions/storage/aliyun_storage.py
+++ b/api/extensions/storage/aliyun_storage.py
@@ -13,13 +13,21 @@ class AliyunStorage(BaseStorage):
def __init__(self, app: Flask):
super().__init__(app)
+
app_config = self.app.config
self.bucket_name = app_config.get('ALIYUN_OSS_BUCKET_NAME')
+ oss_auth_method = aliyun_s3.Auth
+ region = None
+ if app_config.get('ALIYUN_OSS_AUTH_VERSION') == 'v4':
+ oss_auth_method = aliyun_s3.AuthV4
+ region = app_config.get('ALIYUN_OSS_REGION')
+ oss_auth = oss_auth_method(app_config.get('ALIYUN_OSS_ACCESS_KEY'), app_config.get('ALIYUN_OSS_SECRET_KEY'))
self.client = aliyun_s3.Bucket(
- aliyun_s3.Auth(app_config.get('ALIYUN_OSS_ACCESS_KEY'), app_config.get('ALIYUN_OSS_SECRET_KEY')),
+ oss_auth,
app_config.get('ALIYUN_OSS_ENDPOINT'),
self.bucket_name,
- connect_timeout=30
+ connect_timeout=30,
+ region=region,
)
def save(self, filename, data):