Reputation: 652
I can't send an image object in multipart/form-data format without writing and reading it on the disk. This method does not work:
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 thinks that image is too small. But this method works:
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')})
How can I upload image without writing it on the disk?
Upvotes: 2
Views: 263
Reputation: 652
Working code:
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)})
Upvotes: 1