参考资料:

需要获得这几个 key

  • R2_ACCOUNT_ID: 一个账号是一个 ID
  • R2_ACCESS_KEY_ID:
  • R2_SECRET_ACCESS_KEY
  • R2_BUCKET_NAME: Bucket的name

步骤

Step: 创建 Bucket

通过接口访问

step: 生成 API Key

  • R2 → “Manage R2 API Tokens” → Create API Token

  • 选择 Edit 权限 → 选择对应的 Bucket

  • 记录:

    • Access Key ID
    • Secret Access Key
    • Account ID(在 R2 页面右上角)

Step: 配置域名来获得 Public Access

设置自定义域名 s.example.com来获得 public access

Step: 配置 CORS

如果所示的配置项

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[
  {
    "AllowedOrigins": [
      "http://localhost:3000",
      "http://localhost",
      "https://example.com"
    ],
    "AllowedMethods": [
      "GET",
      "POST"
    ]
  }
]
  • 如果配置之后,还是出现跨域问题,请检查是否是 Cloudflare 中的 cache 问题,可以使用purge cache来清理一下 cache 试一下。

Step: 获取 Access Key ID 和 Secret Access Key

创建用户 API token 页面

通过Woker的Bindings访问