基于cf_workers部署IPFS图床(即开即用,秒部署)

同步来源:树洞剪藏 源站剪藏 ID:59 原文地址:https://www.nodeseek.com/post-159672-1
基于cf_workers部署IPFS图床(即开即用,秒部署)
NodeSeek beta 日常 技术 情报 测评 交易 拼车 推广
基于cf_workers部署IPFS图床(即开即用,秒部署)
Adger 楼主 62days ago edited 62days ago in 技术 #0
准备工作:
cloudflare账号 1
pinata_api 1(申请即可)
操作流程:
1、打开CF创建workers
2、点击右上角编辑代码
3、复制以下代码块粘贴至workers项目内(修改line202-203中的pinata_api)
修改项:
1、新增上传图片网关失效自动切换
2、访问网关源修改为支持大陆地区(谢谢站内其他小伙伴提供的公开网关)
成品站点参考
ps:由于是心血来潮,基于chatgpt码出来的;整体美观度不够 还请勿喷
addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) })
async function handleRequest(request) { const url = new URL(request.url)
// 判断是否是上传请求 if (url.pathname === '/upload' && request.method === 'POST') { const formData = await request.formData() const imageFile = formData.get('image')
if (imageFile) { const cid = await uploadToIPFSWithFallback(imageFile) if (cid) { return new Response(`
return new Response('未找到图片/视频', { status: 400 }) }
// 返回美化后的 HTML 上传表单 return new Response(`
setInterval(changeBackground, 10000); // 每 10 秒更换一次背景图 document.addEventListener('DOMContentLoaded', changeBackground);
// 使用多个 IPFS 网关上传图片,并在失败时自动切换 async function uploadToIPFSWithFallback(file) { const gateways = [ { url: 'https://api.pinata.cloud/pinning/pinFileToIPFS', headers: { 'pinata_api_key': 'XXXXX', 'pinata_secret_api_key': 'XXXXX' }}, { url: 'https://gateway.ipfs.io/api/v0/add' }, { url: 'https://api.infura.io:5001/api/v0/add' }, { url: 'https://ipfs.siliconvalley.social/api/v0/add' }, { url: 'https://cloudflare-ipfs.com/api/v0/add' }, { url: 'https://dweb.link/api/v0/add' }, { url: 'https://ipfs.eth.aragon.network/api/v0/add' }, { url: 'https://nftstorage.link/api/v0/add' }, { url: 'https://4everland.io/api/v0/add' }, { url: 'https://ipfs.cyou/api/v0/add' }, { url: 'https://storry.tv/api/v0/add' }, { url: 'https://hardbin.com/api/v0/add' }, { url: 'https://ipfs.runfission.com/api/v0/add' }, { url: 'https://w3s.link/api/v0/add' }, { url: 'https://trustless-gateway.link/api/v0/add' }, { url: 'https://ipfs.ipfs.tech/api/v0/add' }, { url: 'https://gateway.ipfs.btcscan.org/api/v0/add' }, { url: 'https://i0.img2ipfs.com/api/v0/add' }, { url: 'https://ipfs.crossbell.io/api/v0/add' }, { url: 'https://gateway.ipfsscan.io/api/v0/add' } ]
for (const gateway of gateways) {
try {
const cid = await uploadToIPFS(file, gateway.url, gateway.headers || {})
if (cid) {
return cid
}
} catch (error) {
console.error(上传到 ${gateway.url} 失败:, error)
}
}
return null // 如果所有网关都失败,返回 null }
async function uploadToIPFS(file, url, headers) { const formData = new FormData() formData.append('file', file, 'image.png') // 确保文件名存在
const response = await fetch(url, { method: 'POST', headers: headers, body: formData })
if (response.ok) { const data = await response.json() return data.IpfsHash || data.Hash // 返回上传文件的 CID } else { console.error('上传失败', await response.text()) // 输出错误日志 throw new Error('上传失败') } }
IPFS爱跑路图床 | Workers图床搭建教程 | Locvps含aff
正在播放 《 你的眼睛背叛了你的心 》 ━━━━●─────2:40
0 0 8 引用 回复
1 2 3
Adger 楼主 37days ago
#24
@dajie000 #23 我这边秒上传,你是使用我的网站还是自己搭建;如果自己搭建需要去申请一下那个密钥
IPFS爱跑路图床 | Workers图床搭建教程 | Locvps含aff
正在播放 《 你的眼睛背叛了你的心 》 ━━━━●─────2:40
1 0 引用 回复
Joey 62days ago #1
最近都在研究图床啊
Joey Huang Blog博客时不时发疯 TG群来这里找我玩 claw cloud 20%优惠卷 jhb.ovh
0 0 引用 回复
Adger 楼主 62days ago edited 62days ago #2
@Joey #1 吃饱没事干,大家都在研究;所以我就心血来潮研究在cf上白嫖
IPFS爱跑路图床 | Workers图床搭建教程 | Locvps含aff
正在播放 《 你的眼睛背叛了你的心 》 ━━━━●─────2:40
0 0 引用 回复
thex 62days ago #3
pinata_api1(申请即可)
大佬 这个在哪里申请
⭐️快速成功注册甲骨文教程
Every noble work is at first impossible.
0 0 引用 回复
Adger 楼主 62days ago #4
@thex #3 pinata.cloud
IPFS爱跑路图床 | Workers图床搭建教程 | Locvps含aff
正在播放 《 你的眼睛背叛了你的心 》 ━━━━●─────2:40
0 0 引用 回复
chenjia404 62days ago #5
直接用我的api呗,免费还不限量
const api = 'https://cdn.ipfsscan.io/api/v0/add?pin=false'; const formData = new FormData(); formData.append('file', blob);
$.ajax({ url: api, type: 'POST', data: formData, processData: false, contentType: false, success: function(res) {
if (res.Hash) { const imgSrc = 'https://cdn.img2ipfs.com/ipfs/'+res.Hash + "?filename=" + encodeURI(res.Name); console.log(imgSrc); } else { console.error('上传失败'); } }, error: function() { console.error('请求失败'); } });
公益ipfs图床,最大100mb,免注册,多年运行记录 后端300+ipfs节点 文本上传到ipfs 在ipfs上写文章
0 0 引用 回复
Adger 楼主 62days ago #6
@chenjia404 #5 网关可以自行添加,这个只是给一个cf部署的思路
IPFS爱跑路图床 | Workers图床搭建教程 | Locvps含aff
正在播放 《 你的眼睛背叛了你的心 》 ━━━━●─────2:40
0 0 引用 回复
chenjia404 62days ago #7
@Adger #6 这些网关一般都不支持上传。
公益ipfs图床,最大100mb,免注册,多年运行记录 后端300+ipfs节点 文本上传到ipfs 在ipfs上写文章
0 0 引用 回复
泽连斯基 62days ago #8
好贴绑定
0 0 引用 回复
schau 62days ago #9
还是我pages部署比较好
邮箱 | IPFS图床 | 文本转图片 | 身份生成器 | 文本转语音
雄关漫道真如铁,而今迈步从头越。
0 0 引用 回复
Adger 楼主 62days ago #10
@schau #9 你的那个挺不错
IPFS爱跑路图床 | Workers图床搭建教程 | Locvps含aff
正在播放 《 你的眼睛背叛了你的心 》 ━━━━●─────2:40
0 0 引用 回复
1 2 3
内容 预览 对照
支持 markdown语法
鼓励友善发言,禁止人身攻击
xxxxxxxxxx
1
1
AC娘
洋葱头
小黄鸡
发布评论
88
等级 Lv 4 鸡腿 1907 关注 0 通知 0
主题帖 10 评论数 290 粉丝 2 收藏 182 发帖
快捷功能区 推荐阅读 管理记录 幸运抽奖 邀请好友 合作商家 友站链接
所有版块 日常 技术 情报 测评 交易 曝光 拼车 生活 贴图 推广 内版 Dev 无意义 沙盒
📈用户数目📈
目前论坛共有22061位seeker
🎉欢迎新用户🎉
huotuchensha
alanlu
onvo
无欲无求
相关网站 LowEndTalk LowEndSpirit HostLoc ServerHunter
站内导航 关于本站 隐私协议 RSS订阅 sitemap
商业推广 商家申请规则 Premium Provider 合作商家展示
其他平台 电报频道 电报群组
联系我们
Copyright © 2022 - 2024 All rights Reserved