WorkerJS_CloudFlare_ImageBed/python-uploader/test-tingquanxunbao.py
BlueSkyXN 806c4b7227 0.9.4
调整了IPFS图片响应的URL格式
2024-09-20 14:36:49 +08:00

33 lines
946 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
# 设置 API 上传 URL
url = "https://api.tingquanxunbao.com/api/v1/file/upload"
# 设置请求头,假设需要 `Authorization` token可以根据需要添加更多头信息
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN', # 替换为实际的 token如果不需要认证可以去掉此行
}
# 文件路径和类型
file_path = r"F:\Download\20240707-204330.jpg"
file_type = 'image'
# 打开图片文件并上传
with open(file_path, 'rb') as file:
files = {
'file': file, # 文件字段
}
data = {
'file_type': file_type, # 文件类型字段
}
# 发起 POST 请求上传文件
response = requests.post(url, headers=headers, files=files, data=data)
# 检查响应
if response.status_code == 200:
print("文件上传成功:", response.json())
else:
print("文件上传失败,状态码:", response.status_code)
print("响应内容:", response.text)