다음 코드는 Huawei OBS(Object Storage Service)에서 객체를 문서로 로드하는 방법을 보여줍니다.
# Install the required package
# pip install esdk-obs-python
from langchain_community.document_loaders import OBSDirectoryLoader
endpoint = "your-endpoint"
# Configure your access credentials\n
config = {"ak": "your-access-key", "sk": "your-secret-key"}
loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint, config=config)
loader.load()

로드할 Prefix 지정하기

bucket에서 특정 prefix를 가진 객체를 로드하려면 다음 코드를 사용할 수 있습니다:
loader = OBSDirectoryLoader(
    "your-bucket-name", endpoint=endpoint, config=config, prefix="test_prefix"
)
loader.load()

ECS에서 인증 정보 가져오기

langchain이 Huawei Cloud ECS에 배포되어 있고 Agency가 설정되어 있다면, loader는 access key와 secret key 없이 ECS에서 직접 security token을 가져올 수 있습니다.
config = {"get_token_from_ecs": True}
loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint, config=config)
loader.load()

Public Bucket 사용하기

bucket의 bucket policy가 익명 액세스를 허용하는 경우(익명 사용자가 listBucketGetObject 권한을 가진 경우), config parameter를 구성하지 않고 직접 객체를 로드할 수 있습니다.
loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint)
loader.load()

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I