我不能以multipart / form-data格式发送图像对象而无需在磁盘上写入和读取它。此方法不起作用:
response = requests.get(offer['picture'])
if not response.ok:
print('Error!', response)
continue
image = response.content
response = requests.post(upload_url, files={'file': image})
API认为图像太小。但这种方法有效:
response = requests.get(offer['picture'])
if not response.ok:
print('Error!', response)
continue
image = response.content
with open('test.jpg', 'wb') as file:
file.write(image)
response = requests.post(upload_url, files={'file': open('test.jpg', 'rb')})
如何在不将图像写入磁盘的情况下上传图像?
答案 0 :(得分:1)
工作代码:
response = requests.get(offer['picture'])
if not response.ok:
print('Error!', response)
continue
image = response.content
response = requests.post(upload_url, files={'file': ('image.jpg', image)})