首页 > 解决方案 > 无法将图像上传到 Ghost CMS

问题描述

有人知道使用 python 将图像上传到 Ghost CMS 吗?

url = "https://analisa.ifxid.trade/ghost/api/v3/admin/images/upload/"
headers = {'Authorization': 'Ghost {}'.format(token.decode()),'Content-Type': 'form-data;'}
files = {'file':('ifxb.png', open('ifxb.png', 'rb'))}
r = requests.post(url, headers=headers, files=files)
print(r.text)

结果

{"errors":[{"message":"Please select an image.","context":null,"type":"ValidationError","details":null,"property":null,"help":null,"code":null,"id":"e114da60-d7c9-11ea-972e-97f9c75664c6"}]}

标签: pythonghost-blog

解决方案


邮递员给了我答案,文件字典中缺少图片的内容类型。它现在应该可以工作了。

url = "https://analisa.ifxid.trade/ghost/api/v3/admin/images/upload/"
headers = {'Authorization': 'Ghost {}'.format(token.decode()),'Content-Type': 'form-data;'}
files = {'file':('ifxb.png', open('ifxb.png', 'rb'), 'image/png')}
r = requests.post(url, headers=headers, files=files)
print(r.text)

推荐阅读