I've got my own site, but paid image hosting felt a bit pricey, so I tried rolling my own. Messed around with a bunch of stuff online and none of it felt great, so I hacked together a Cloudflare R2 + TG dual-active (backup) setup with AI, and it turned out decent enough to share.
Grab it and tinker with it yourself if you need it.
Baidu link: https://pan.baidu.com/s/1jz7-33xO2F062s5IF0DosA?pwd=jjrg
Quark link: https://pan.quark.cn/s/26856336f9fd
You don't need any dev environment or command line on your computer at all — just click around in GitHub and the Cloudflare Pages dashboard, and you can get "ZYW image host" fully deployed in 10 minutes.
Step 1: Upload the source to your GitHub repo
● Unzip the source archive: unzip zyw_tuchuang_v2.5_opensource.zip on your computer, open the zyw-tuchuang folder inside, and you'll see public, functions, package.json and so on.
● Create a new private repo: log in and, following GitHub's create-a-repo guide, click the + in the top right and choose New repository, name it zyw-tuchuang, tick Private (safer that way), and click Create repository at the bottom.
● Drag-and-drop upload in the browser: on the new empty repo page, click uploading an existing file (see GitHub's web upload docs), and drag all the files and subfolders from inside the zyw-tuchuang folder into the box (note: drag public, functions etc. in directly — don't wrap them in an extra folder layer).
● Commit the code: once all the progress bars finish, just click the green Commit changes button at the bottom of the page.
Step 2: Create the database and bucket in Cloudflare
After logging into the Cloudflare dashboard, you first need to create a KV namespace for the image index and an R2 bucket for the original image files:
● Create the KV index space: in the left menu go to Storage & Databases → KV (see Cloudflare's Workers KV getting-started guide), click Create a namespace (or Create instance), enter zyw-image-index as the name, and click Add to finish.
● Create the R2 image bucket: in the left menu go to R2 Object Storage → Overview (see Cloudflare's R2 bucket creation guide), click Create bucket, enter zyw-images as the name, leave the location on default auto, and click Create bucket (R2 gives you 10GB free per month with no egress fees).
● Set up a Telegram bot (optional dual backup): if you want "R2 + Telegram dual-active backup", open the official @BotFather in Telegram and send /newbot to get a TG_BOT_TOKEN, then add the bot to your private channel as an admin to get the channel ID (usually starts with -100); skip this if you're only using R2.
Step 3: Connect the repo to Cloudflare Pages and deploy for the first time
● Go to the Pages creation page: in the Cloudflare left menu click Compute (Workers) → Workers & Pages, click Create in the top right, then switch to the Pages tab at the top and choose Connect to Git (see Cloudflare's Pages Git integration docs).
● Authorize and pick the repo: click to connect your GitHub account, select the zyw-tuchuang repo you just created from the list, and click Begin setup.
● Fill in the build config:
○ Project name: keep zyw-tuchuang (or use your own).
○ Build command: leave it empty — this source has no bloated bundler, so nothing goes here.
○ Build output directory: enter public (required, points to where the frontend lives).
● Run the first deploy: click Save and Deploy at the bottom and wait about 20 seconds for the success message.
Step 4: Bind storage and environment variables (the most important step)
Once the first deploy succeeds, click Continue to project to open the project page, then go through Settings at the top to configure the following two things (see Cloudflare's Pages bindings docs):
Where to configure | Binding type / Variable name | Value or selection | What it does
Settings → Bindings → Add → KV namespace | IMAGE_INDEX | Select the zyw-image-index created in step 2 | Stores the image short-link mapping and login brute-force counters (required, name must be all caps)
Settings → Bindings → Add → R2 bucket | ZYW_R2_BUCKET | Select the zyw-images created in step 2 | Stores uploaded HD images and video files (required, name must be all caps)
Settings → Environment variables → Add | UPLOAD_AUTH_PASSWORD | e.g. zyw888888 (pick your own strong password) | Sets the password gate for access and uploads; if you don't add this, the whole site is open for passwordless uploads
Settings → Environment variables → Add | SESSION_SECRET | any long random string (e.g. zyw_2026_abcdefg) | Encrypts the login cookie and prevents forged sessions
Settings → Environment variables → Add | STORAGE_DRIVER | r2 (R2 only) or dual (R2 + TG dual-active) | r2 is the simplest if you only use R2; use dual to turn on the backup
Settings → Environment variables → Add | TG_BOT_TOKEN | the token generated by @BotFather | Only needed when STORAGE_DRIVER is set to dual or telegram
Settings → Environment variables → Add | TG_CHAT_ID | your Telegram channel ID (e.g. -100123456) | Only needed when the Telegram storage channel is enabled
Binding R2: Cloudflare Dashboard → R2 → Create bucket (e.g. zyw-images) → back to the Pages project → Settings → Bindings → Add → R2 bucket, variable name ZYW_R2_BUCKET
Binding KV (not mandatory). Pages → Settings → Bindings → Add → KV namespace, variable name IMAGE_INDEX. The free quota is more than enough; the main point is to get login rate limiting working, otherwise someone can brute-force your upload password forever.
Step 5: Re-trigger the deploy so the config takes effect
● Re-run the latest deployment: since bindings and environment variables only take effect after a reload, go to the Deployments tab at the top of the project, find the three-dot (...) button to the right of the first deployment record, and click Retry deployment.
● Bind your own domain (strongly recommended): once the retried deployment turns green/Active, you can use the *.pages.dev URL Cloudflare assigned you right away; if you're worried about the free domain changing and breaking your hotlinks, bind your own domain under Custom domains at the top of the project, then change "same-domain direct link domain" in the top right of the upload page to your domain — after that you can bulk upload in one click and copy BBCode, HTML, Markdown and direct links.
If you can't find a button at some step or hit an error message, send me a screenshot or the error text and I'll walk you through it step by step.
自己整了个网站,但是用付费的图床感觉有点小贵,就尝试了下,自己整一个,网上鼓捣了好多感觉都不咋理想,自己用AI鼓捣了一个 Cloudflare R2+TG 双活(备份)的,感觉还行,分享给大家。
需要的自己下载去鼓捣吧。
百度链接:https://pan.baidu.com/s/1jz7-33xO2F062s5IF0DosA?pwd=jjrg
夸克链接:https://pan.quark.cn/s/26856336f9fd
你完全不需要在电脑上安装编程环境或敲命令行,只需通过 GitHub 和 Cloudflare Pages 网页后台点点鼠标,10 分钟内即可完成“ZYW图床”全栈上线。
第一步:将源码上传到你的 GitHub 仓库
● 解压源码压缩包:在电脑上解压刚才下载的 zyw_tuchuang_v2.5_opensource.zip,打开里面的 zyw-tuchuang 文件夹,你会看到 public、functions、package.json等文件。
● 新建私有仓库:登录并参考 GitHub 新建仓库指南,点击右上角 + 号选择 New repository,仓库名称填 zyw-tuchuang,勾选 Private(设为私有更安全),点击底部的 Create repository。
● 网页端拖拽上传代码:在新建好的空仓库页面中,点击 uploading an existing file(参考 GitHub 网页上传文件文档),把 zyw-tuchuang 文件夹里面的所有文件和子文件夹(注意是直接拖入 public、functions等,不要在最外层多套一层文件夹)一起拖进网页框内。
● 提交保存代码:等待文件进度条全部走完后,直接点击页面底部的绿色按钮 Commit changes。
第二步:在 Cloudflare 创建数据库与存储桶
登录 Cloudflare 控制台后,需要先创建用来存图片索引的 KV 数据库和存图片原文件的 R2 存储桶:
● 创建 KV 索引空间:在左侧菜单进入 Storage & Databases (存储和数据库) → KV(参考 Cloudflare Workers KV 入门指南),点击 Create a namespace(或 Create instance),名称填写 zyw-image-index,点击 Add 完成创建。
● 创建 R2 图片存储桶:在左侧菜单进入 R2 Object Storage → Overview(参考 Cloudflare R2 创建存储桶指南),点击 Create bucket,名称填写 zyw-images,位置保持默认自动,点击 Create bucket 完成创建(R2 每月提供 10GB 免费额度且免流量费)。
● 准备 Telegram 机器人(可选双备份):如果你希望开启“R2 + Telegram 双活备份”,可在 Telegram 中打开官方 @BotFather 发送 /newbot 获取 TG_BOT_TOKEN,并将机器人拉入你的私有频道设为管理员以获取频道 ID(通常以 -100 开头);若只用 R2 存储可跳过此步。
第三步:在 Cloudflare Pages 连接仓库并首次部署
● 进入 Pages 创建页:在 Cloudflare 左侧菜单点击 Compute (Workers) → Workers & Pages,点击右上角 Create,然后切换到顶部的 Pages 标签页,选择 Connect to Git(参考 Cloudflare Pages Git 集成文档)。
● 授权并选择仓库:点击连接你的 GitHub 账号,在列表中选中刚才创建的 zyw-tuchuang 仓库,点击 Begin setup。
● 填写构建配置:
○ 配置项目名称 (Project name):保持 zyw-tuchuang(或自定义名称)。
○ 留空构建命令 (Build command):本源码已消除臃肿打包框架,此项留空不填即可。
○ 填写输出目录 (Build output directory):输入 public(必填,指向前端网页所在目录)。
● 执行首次部署:点击底部的 Save and Deploy,等待约 20 秒即可看到部署成功的提示。
第四步:绑定存储与环境变量(最关键一步)
首次部署成功后,点击 Continue to project 进入项目详情页,依次点击顶部 Settings (设置) 配置以下两项(参考 Cloudflare Pages 绑定配置文档):
配置位置 绑定类型 / 变量名 填写值或选择项 作用说明
Settings → Bindings → Add → KV namespace IMAGE_INDEX 选择第二步创建的 zyw-image-index 存储图片短链映射与登录防爆破计数(必填,名字必须全大写)
Settings → Bindings → Add → R2 bucket ZYW_R2_BUCKET 选择第二步创建的 zyw-images 存储上传的高清图片与视频文件(必填,名字必须全大写)
Settings → Environment variables → Add UPLOAD_AUTH_PASSWORD 例如 zyw888888(自定义强密码) 设置访问与上传门禁密码;若不添加此变量则全站免密公开上传
Settings → Environment variables → Add SESSION_SECRET 随便填一串长字符(如 zyw_2026_abcdefg) 用于加密登录 Cookie,防止伪造会话
Settings → Environment variables → Add STORAGE_DRIVER 填 r2(仅用 R2)或 dual(R2+TG 双活) 只用 R2 时填 r2 最省心;开启双备份时填 dual
Settings → Environment variables → Add TG_BOT_TOKEN 填入 @BotFather 生成的 Token 仅当 STORAGE_DRIVER 设为 dual 或 telegram 时需要填写
Settings → Environment variables → Add TG_CHAT_ID 填入你的 Telegram 频道 ID(如 -100123456) 仅当启用 Telegram 存储通道时需要填写
绑定R2:Cloudflare Dashboard → R2 → Create bucket(如 zyw-images)→ 回到 Pages 项目 → Settings → Bindings → Add → R2 bucket,变量名填 ZYW_R2_BUCKET
绑定 KV(不是必须)。Pages → Settings → Bindings → Add → KV namespace,变量名填 IMAGE_INDEX。免费额度完全够用,主要目的是让登录限流恢复,否则有人能对你的上传密码无限次爆破。
第五步:重新触发部署使配置生效
● 重跑最新部署:由于修改绑定和环境变量后需要重新加载才能生效,请点击项目顶部的 Deployments (部署) 标签页,找到第一条部署记录右侧的 三个点 (...) 按钮,点击 Retry deployment。
● 绑定自有域名(强烈推荐):待重试部署变为绿色 Active 后,你就可以直接访问 Cloudflare 分配的 *.pages.dev 网址使用图床;如果担心免费域名变动导致外链失效,可在项目顶部的 Custom domains (自定义域) 中绑定你自己的域名,之后在上传页右上角将“同域直链域名”改为你的域名,即可一键批量上传并复制 BBCode、HTML、Markdown 和直链代码。
如果在操作某一步时找不到按钮或遇到报错提示,随时把截图或报错文字发给我,我带你一步步排查。
Translated by AI from 简体中文Original (简体中文)
可以共享、可以push的免费邮箱,更可使用自定义域名,完美契合您的各项需求。
22 replies
Sort order