内容提要
文章讲解了如何使用 rclone 和 GitHub Actions 将图片从 Cloudflare R2 同步到本地。步骤包括安装 rclone、获取 Cloudflare R2 API 访问信息、配置 rclone 和 R2 存储桶、下载图片到本地,以及设置 GitHub Actions 实现自动同步。这样可以在图片上传到 GitHub 后,自动同步到图床平台,简化管理流程。
关键要点
-
文章介绍如何使用 rclone 和 GitHub Actions 将图片从 Cloudflare R2 同步到本地。
-
步骤包括安装 rclone、获取 Cloudflare R2 API 访问信息、配置 rclone 和 R2 存储桶。
-
下载图片到本地,并设置 GitHub Actions 实现自动同步。
-
Cloudflare R2 提供免费套餐,存储费用和操作费用详细说明。
-
安装 rclone 的方法:在 Linux/macOS 上使用 curl 命令,在 Windows 上下载并配置 PATH。
-
获取 Cloudflare R2 API 访问信息,包括 Access Key 和 Secret Key。
-
使用 rclone config 命令配置 Cloudflare R2 作为存储后端。
-
使用 rclone 命令将图片从 Cloudflare R2 下载到本地。
-
验证同步结果,确保 R2 上的图片已成功下载到本地。
-
获取 rclone Config 信息并进行 Base64 编码以备后用。
-
在 GitHub 仓库中设置 GitHub Actions 以实现自动同步。
-
添加必要的 Action 变量和 secrets,以便 GitHub Actions 正常运行。
-
验证 GitHub Actions 是否成功运行,并检查 Cloudflare R2 中的文件。
延伸问答
如何安装 rclone?
在 Linux/macOS 上使用命令:curl https://rclone.org/install.sh | sudo bash;在 Windows 上下载并配置 PATH。
如何获取 Cloudflare R2 的 API 访问信息?
登录 Cloudflare 仪表板,点击 R2 对象存储 - 概述,创建 API 令牌,记录 Access Key 和 Secret Key。
如何配置 rclone 以连接 Cloudflare R2?
使用 rclone config 命令,选择创建新连接,输入名称和存储类型,提供 Access Key 和 Secret Key,设置 endpoint。
如何将图片从 Cloudflare R2 下载到本地?
使用命令 rclone copy cloudflare_r2:my-images /path/to/local/folder 将图片同步到本地目录。
如何设置 GitHub Actions 实现自动同步?
在 GitHub 仓库的 .github/workflows 中添加 Cloudflare-r2.yml 文件,配置必要的 Action 变量和 secrets。
Cloudflare R2 的存储费用是怎样的?
Cloudflare R2 提供10 GB/月的免费存储,超出部分0.015美元/GB,操作费用根据类型不同而异。