SuperAPI AI Directory

baiducloud-bos

Testing & quality

View repository

Updated 10-15 21:05

About this skill

Baidu AI Cloud BOS Skill

Manage Baidu AI Cloud Object Storage (BOS) via Node.js SDK scripts + bcecmd tool.

First Use — Automatic Setup

When the user first requests a BOS operation, follow this process:

Step 1: Check Current Status

{baseDir}/scripts/setup.sh --check-only

If the output shows everything is OK (SDK installed, credentials configured), skip to "Execution Strategy".

Step 2: If Not Configured, Guide the User to Provide Credentials

Tell the user:

I need your Baidu AI Cloud credentials to connect to the BOS storage service. Please provide:

  1. AccessKeyId — Baidu Cloud AK
  2. SecretAccessKey — Baidu Cloud SK
  3. Endpoint — BOS service endpoint (e.g., bj.bcebos.com、gz.bcebos.com、su.bcebos.com)
  4. Bucket — Bucket name (e.g., my-bucket)
  5. StsToken(Optional) — SessionToken for temporary security credentials

You can find the keys at Baidu AI Cloud Console > Security Authentication > Access Key , and view bucket information at BOS Console .

Endpoint Reference Table:

Region Endpoint
Beijing bj.bcebos.com
Guangzhou gz.bcebos.com
Suzhou su.bcebos.com
Baoding bd.bcebos.com
Hong Kong hkg.bcebos.com

Step 3: After the User Provides Credentials, Run Automatic Setup

{baseDir}/scripts/setup.sh --ak "<AccessKeyId>" --sk "<SecretAccessKey>" --endpoint "<Endpoint>" --bucket "<Bucket>"

The script will automatically:

  • Check and install @baiducloud/sdk(Node.js SDK)
  • Check whether bcecmd is installed
  • Persist credentials to ~/.config/openclaw/baidu-cloud-bos/credentials.json(permissions 600)
  • Export credentials to the current session environment variables
  • Configure bcecmd (if installed)
  • Verify the BOS connection

Credential reading priority:Environment variables > credentials.json configuration file. Subsequent new sessions do not require reconfiguration.

Execution Strategy

The two methods fall back by priority to ensure operations can always be completed:

  1. Method 1: Node.js SDK Script(Preferred) — via scripts/bos_node.mjs to perform storage operations
  2. Method 2: bcecmd Command Line — perform storage operations via shell commands, supports directory synchronization
Node.js + @baiducloud/sdk 可用?
  ├─ 是 → 使用方式一(单文件操作,JSON 输出,适合程序化处理)
  └─ 否 → bcecmd 可用?(which bcecmd)
            ├─ 是 → 使用方式二(全功能,含目录同步)
            └─ 否 → 运行 setup.sh 安装

Determine Method 1:node -e "require('@baiducloud/sdk')" If successful, it is available. Determine Method 2:which bcecmd If there is output, it is available.


Method 1: Node.js SDK Script (Preferred)

Official documentation: https://cloud.baidu.com/doc/BOS/s/Djwvyrhiw

When using Method 1, via scripts/bos_node.mjs to perform storage operations. Credential reading priority: environment variables > ~/.config/openclaw/baidu-cloud-bos/credentials.json。

Supported credential sources:

  • Environment variables(Preferred):BCE_ACCESS_KEY_ID / BCE_SECRET_ACCESS_KEY / BCE_BOS_ENDPOINT / BCE_BOS_BUCKET(Required),BCE_STS_TOKEN(Optional, temporary credentials)
  • Configuration file(Fallback):~/.config/openclaw/baidu-cloud-bos/credentials.json

Common Commands

The following omits the node {baseDir}/scripts/bos_node.mjs prefix. Full format:node {baseDir}/scripts/bos_node.mjs <action> [options]

# 上传文件
upload --file /path/to/file.jpg --key remote/path/file.jpg

# 上传字符串内容
put-string --content "文本内容" --key remote/file.txt --content-type "text/plain"

# 下载文件
download --key remote/path/file.jpg --output /path/to/save/file.jpg

# 列出文件
list --prefix "images/" --max-keys 100

# 获取签名 URL
sign-url --key remote/path/file.jpg --expires 3600

# 图片处理:亮度调整(-100 到 100)
sign-url --key remote/path/image.jpg --bright -5

# 图片处理:对比度调整(-100 到 100)
sign-url --key remote/path/image.jpg --contrast -30

# 图片处理:模糊(半径,标准差,各 1-50)
sign-url --key remote/path/image.jpg --blur 2,50

# 图片处理:旋转(-360 到 360,正数顺时针)
sign-url --key remote/path/image.jpg --rotate 90

# 图片处理:按 EXIF 自适应旋转
sign-url --key remote/path/image.jpg --auto-orient 1

# 图片处理:多操作链式(便捷 flag 可组合)
sign-url --key remote/path/image.jpg --bright 10 --contrast 20

# 图片处理:多参数操作用 --process 直传(缩放、裁剪、水印等)
sign-url --key remote/path/image.jpg --process "image/resize,m_lfit,w_800"
sign-url --key remote/path/image.jpg --process "image/crop,x_10,y_10,w_200,h_200"
sign-url --key remote/path/image.jpg --process "image/circle,r_100"
sign-url --key remote/path/image.jpg --process "image/rounded-corners,r_50"
sign-url --key remote/path/image.jpg --process "image/quality,q_80"
sign-url --key remote/path/image.jpg --process "image/watermark,text_aGVsbG8=,g_9"
sign-url --key remote/path/image.jpg --process "image/bright,b_10/resize,m_lfit,w_800"

# 获取图片详细信息(宽高、格式、色彩深度、透明通道等)
# 注意:sign-url 只生成 URL,需配合 curl 获取结果
sign-url --key remote/path/image.jpg --process "image/info"
# curl -s "$(上述命令输出的 url)"

# resize 模式:lfit=等比缩小至框内,mfit=等比放大至框外,fill=填充裁剪,pad=填充空白,fixed=强制宽高
# 水印 text 参数需 URL-safe Base64 编码:标准 base64 后将 + → -,/ → _,去掉尾部 =

# 查看文件信息(HEAD)
head --key remote/path/file.jpg

# 删除文件
delete --key remote/path/file.jpg

# 复制文件(同桶或跨桶)
copy --source-bucket <bucket> --source-key <key> --key <dest-key>

# 列出所有 Bucket
list-buckets

All commands output in JSON format,success: true indicates success, exit code 0.

Limitations

Only single-file operations are supported,does not supportrecursive directory upload/download/sync (use method two, bcecmd). Image processing is a feature exclusive to method one.


Method Two: bcecmd command line

Official documentation: https://cloud.baidu.com/doc/BOS/s/kmcn3zrup

Use when method one is unavailable. bcecmd is Baidu Cloud's official command-line tool, supporting advanced features such as directory sync.

Initial configuration

bcecmd --conf-path ~/.bcecmd configure \
  --access-key <AK> \
  --secret-key <SK> \
  --domain <Endpoint>

Configuration files are saved in ~/.bcecmd/credentials and ~/.bcecmd/config。

Common commands

# 上传文件
bcecmd bos cp /path/to/file.jpg bos:/<bucket>/remote/path/file.jpg

# 上传目录(递归)
bcecmd bos cp /path/to/folder/ bos:/<bucket>/remote/folder/ --recursive

# 下载文件
bcecmd bos cp bos:/<bucket>/remote/path/file.jpg /path/to/save/file.jpg

# 下载目录(递归)
bcecmd bos cp bos:/<bucket>/remote/folder/ /path/to/save/ --recursive

# 列出文件
bcecmd bos ls bos:/<bucket>/images/

# 删除文件
bcecmd bos rm bos:/<bucket>/remote/path/file.jpg

# 递归删除目录
bcecmd bos rm bos:/<bucket>/remote/folder/ --recursive --yes

# 同步本地目录到 BOS
bcecmd bos sync /path/to/local/ bos:/<bucket>/remote/ --delete

# 同步 BOS 目录到本地
bcecmd bos sync bos:/<bucket>/remote/ /path/to/local/ --delete

# 查看文件元信息
bcecmd bos head bos:/<bucket>/remote/path/file.jpg

# 获取签名 URL(默认 1800 秒,-e 后直接跟秒数无空格;-e-1 为永久有效)
bcecmd bos gen_signed_url bos:/<bucket>/remote/path/file.jpg -e3600
bcecmd bos gen_signed_url bos:/<bucket>/remote/path/file.jpg -e-1

# 列出所有 Bucket
bcecmd bos ls

# 创建 Bucket
bcecmd bos mb bos:/<bucket>

# 删除 Bucket(必须为空)
bcecmd bos rb bos:/<bucket>

# 常用全局参数
# --exclude <PATTERN>  排除匹配的文件(支持上传/下载/同步)
# --include <PATTERN>  仅包含匹配的文件
# --conf-path <PATH>   指定配置目录(默认 ~/.bcecmd)
# 示例:同步时排除日志文件
bcecmd bos sync /path/to/local/ bos:/<bucket>/remote/ --delete --exclude "*.log"

Advantages

  • Directory sync:bcecmd bos sync supports incremental sync,--delete deletes redundant remote files
  • Recursive operations:--recursive supports directory-level upload/download/delete
  • Large files: automatic multipart upload
  • Bucket management: create/delete Bucket

Feature comparison table

Feature Method One Node.js SDK Method Two bcecmd
Upload file ✅ ✅
Upload string/content ✅ ❌
Download file ✅ ✅
List files ✅ ✅
Get signed URL ✅ ✅
Image processing (signed URL) ✅ ❌
Delete file ✅ ✅
View file information ✅ ✅
Copy file ✅ ✅ (cp command)
Recursive directory upload/download ❌ ✅
Directory sync (incremental) ❌ ✅
Bucket management ✅(list) ✅ (create/delete/list)
JSON structured output ✅ ❌

Usage guidelines

  1. Run first on first use {baseDir}/scripts/setup.sh --check-only to check the environment
  2. Credentials are not displayed in plain text: guide users to set them themselves via setup.sh or by editing the configuration file
  3. All file paths(--key/BOS paths) are relative paths within the bucket, such as images/photo.jpg
  4. bcecmd path format:bos:/<bucket>/path/to/file, note the bos:/ prefix
  5. Actively obtain the link after upload: after upload is complete, call sign-url(method one) or gen_signed_url(method two) to return the access link
  6. Error handling: when a call fails, first use setup.sh --check-only to diagnose environment issues
  7. For large batch operations, prefer bcecmd: method two is recommended for scenarios such as directory sync and batch upload
  8. Method one script source codesee scripts/bos_node.mjs
  9. API reference documentationsee references/api_reference.md