mirror of
https://github.com/BlueSkyXN/WorkerJS_CloudFlare_ImageBed.git
synced 2024-11-15 19:22:21 +08:00
7fb7a7a914
tx接口挂了,前端下掉。然后对ipfs-fix.js新增多个ipfs网关,不过他们的可用性不高
32 lines
1010 B
Python
32 lines
1010 B
Python
import requests
|
||
|
||
# 上传图片接口的URL
|
||
upload_url = "https://openai.weixin.qq.com/weixinh5/webapp/h774yvzC2xlB4bIgGfX2stc4kvC85J/cos/upload"
|
||
|
||
# 图片路径
|
||
image_path = r"F:\Download\ecabfc9aa7dace978229f8563ab5c856fe530eea.jpg"
|
||
|
||
# 准备上传的文件,模拟 PHP 中的 `CURLFile`,用 `files` 参数传递文件
|
||
files = {
|
||
'media': ('ecabfc9aa7dace978229f8563ab5c856fe530eea.jpg', open(image_path, 'rb'), 'image/jpeg')
|
||
}
|
||
|
||
# 发送POST请求,上传图片
|
||
try:
|
||
response = requests.post(upload_url, files=files)
|
||
response.raise_for_status() # 检查请求是否成功
|
||
|
||
# 解析响应数据
|
||
response_data = response.json()
|
||
if 'url' in response_data:
|
||
print("图片上传成功,访问URL为:", response_data['url'])
|
||
else:
|
||
print("上传失败,服务器未返回URL:", response_data)
|
||
print(response)
|
||
|
||
except requests.exceptions.RequestException as e:
|
||
print(f"图片上传失败: {e}")
|
||
finally:
|
||
# 关闭文件
|
||
files['media'][1].close()
|