

最近发现很多常用的图床失效了,看见很多小伙伴们在找有稳定靠谱的图床替代方案,最好可以提供api接口的。


谷歌搜索github上图片托管(image-host)的相关话题,发现Telegraph-Image这个项目


这个项目是国人开发的,教程文档也很清晰,操作起来简单,那就选这个吧!
项目中有详细的教程步骤,图文教程可以直接看项目的方法,视频教程可以直接在B站搜索cloudflare图床关键字

图文教程链接: https://github.com/cf-pages/Telegraph-Image
视频教程链接: https://www.bilibili.com/video/BV13N411z7Lu/
部署好之后,cloudflare会生成一个网页链接,打开后就可以上传图片并生成图片链接地址了!

当然,最好能够提供api接口,直接发送个post请求,然后直接返回图片地址,这样就在影刀里欢快调用指令上传图片啦!看了下文档,修改了下代码,就可以直接调用 api 啦!
API代码如下:
# filepath是本地图片的文件路径
# base_url用于上传图片的网址,如上图的*.Telegraph-Image-alr.pages.dev
def get_img_url(filepath,base_url):
with open(filepath, 'rb') as file:
files = {'file': file}
response = requests.post(f'{base_url}/upload', files=files)
if response.status_code == 200:
image_url = f"{base_url}/file/{response.text.split('/')[-1][:-3]}" # 假设服务器返回图片链接
return image_url
else:
return "上传失败"请根据下面代码生成指令
```
def get_img_url(filepath,base_url):
with open(filepath, 'rb') as file:
files = {'file': file}
response = requests.post(f'{base_url}/upload', files=files)
if response.status_code == 200:
image_url = f"{base_url}/file/{response.text.split('/')[-1][:-3]}" # 假设服务器返回图片链接
return image_url
else:
return "上传失败"
```