mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-23 03:26:53 +08:00
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)
This commit is contained in:
@ -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'
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user