Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

图床API正确的使用方式,已经验证通过~~ #206

Open
lonrencn opened this issue Sep 28, 2024 · 0 comments
Open

图床API正确的使用方式,已经验证通过~~ #206

lonrencn opened this issue Sep 28, 2024 · 0 comments

Comments

@lonrencn
Copy link

lonrencn commented Sep 28, 2024

1、在”图床安全“中找到”API上传“,一定要点保存
image

2、在”API设置“中添加token
image

有这两个操作,才能正确使用api上传功能

import requests

# 本地图片文件路径
image_path = "/your_path/ComfyUI_00043_.png"

# token值,需从实际来源获取(例如读取tokenList文件)
token = "your_token_value"

# 目标URL
check_url = "https://your_url/api/public.php"
upload_url = "https://your_url/api/index.php"

# 构建请求参数
files = {'image':open(image_path, 'rb')}
check_content = 'free_space'
url = f"{check_url}?show={check_content}"
data = {'token':token}
# 发送get请求查询图床状态   这里也需要在”图床安全“中打开设置
response = requests.get(url)
print(url)
print(response.text)

# 发送POST请求上传文件
response = requests.post(upload_url, files=files, data=data)

# 检查响应状态码
if response.status_code == 200:
    print(response.status_code)
    print(response.json())
    
    print("Upload successful.")
else:
    print(f"Upload failed with status code {response.status_code}.")`

请愉快的玩耍吧!!
感谢开发者无偿的分享

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant