From 2d9e7b4acd2e263d10a46c9b067b0ffeaf8197a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=9A=E6=95=B2=E4=BB=A3=E7=A0=81=E7=9A=84=E5=96=B5?= Date: Thu, 22 Jan 2026 11:43:55 +0800 Subject: [PATCH] Fix: aliyun oss need to use s3 signature_version (#12766) ### What problem does this PR solve? Aliyun OSS do not support boto s4 signature_version which will lead to an error: ``` botocore.exceptions.ClientError: An error occurred (InvalidArgument) when calling the PutObject operation: aws-chunked encoding is not supported with the specified x-amz-content-sha256 value ``` According to aliyun oss docs, oss_conn need to use s3 signature_version. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- conf/service_conf.yaml | 4 +++- docker/.env | 1 + docker/service_conf.yaml.template | 2 ++ rag/utils/oss_conn.py | 14 ++++++++++++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/conf/service_conf.yaml b/conf/service_conf.yaml index 04a316488..b303d69ae 100644 --- a/conf/service_conf.yaml +++ b/conf/service_conf.yaml @@ -68,9 +68,11 @@ user_default_llm: # oss: # access_key: 'access_key' # secret_key: 'secret_key' -# endpoint_url: 'http://oss-cn-hangzhou.aliyuncs.com' +# endpoint_url: 'https://s3.oss-cn-hangzhou.aliyuncs.com' # region: 'cn-hangzhou' # bucket: 'bucket_name' +# signature_version: 's3' +# addressing_style: 'virtual' # azure: # auth_type: 'sas' # container_url: 'container_url' diff --git a/docker/.env b/docker/.env index 0ba5f8c90..ef8edbcb6 100644 --- a/docker/.env +++ b/docker/.env @@ -227,6 +227,7 @@ EMBEDDING_BATCH_SIZE=${EMBEDDING_BATCH_SIZE:-16} # ENDPOINT=http://oss-cn-hangzhou.aliyuncs.com # REGION=cn-hangzhou # BUCKET=ragflow65536 +# # A user registration switch: # - Enable registration: 1 diff --git a/docker/service_conf.yaml.template b/docker/service_conf.yaml.template index 2b6f661da..f283f0853 100644 --- a/docker/service_conf.yaml.template +++ b/docker/service_conf.yaml.template @@ -81,6 +81,8 @@ user_default_llm: # region: '${REGION}' # bucket: '${BUCKET}' # prefix_path: '${OSS_PREFIX_PATH}' +# signature_version: 's3' +# addressing_style: 'virtual' # azure: # auth_type: 'sas' # container_url: 'container_url' diff --git a/rag/utils/oss_conn.py b/rag/utils/oss_conn.py index 60f7e6e96..7137094f0 100644 --- a/rag/utils/oss_conn.py +++ b/rag/utils/oss_conn.py @@ -16,7 +16,6 @@ import logging import boto3 from botocore.exceptions import ClientError -from botocore.config import Config import time from io import BytesIO from common.decorator import singleton @@ -34,6 +33,8 @@ class RAGFlowOSS: self.region = self.oss_config.get('region', None) self.bucket = self.oss_config.get('bucket', None) self.prefix_path = self.oss_config.get('prefix_path', None) + self.signature_version = self.oss_config.get('signature_version', None) + self.addressing_style = self.oss_config.get('addressing_style', None) self.__open__() @staticmethod @@ -62,6 +63,15 @@ class RAGFlowOSS: pass try: + config_kwargs = {} + + if self.signature_version: + config_kwargs['signature_version'] = self.signature_version + if self.addressing_style: + config_kwargs['s3'] = { + 'addressing_style': self.addressing_style + } + # Reference:https://help.aliyun.com/zh/oss/developer-reference/use-amazon-s3-sdks-to-access-oss self.conn = boto3.client( 's3', @@ -69,7 +79,7 @@ class RAGFlowOSS: aws_access_key_id=self.access_key, aws_secret_access_key=self.secret_key, endpoint_url=self.endpoint_url, - config=Config(s3={"addressing_style": "virtual"}, signature_version='v4') + config=config_kwargs ) except Exception: logging.exception(f"Fail to connect at region {self.region}")