Having following code for POST
request with file attached:
file = open(file_name, 'rb')
files = {'file': file}
import requests
res = requests.request(method='POST', url=port_url, files=files, data=params)
file
here of type <class '_io.BufferedReader'>
.
Now I am trying to impliment similar with file body received by me from incoming email attachment as bytes array (want to avoid storing file to local disk):
file = file_body
files = {'file': file}
import requests
res = requests.request(method='POST', url=port_url, files=files, data=params)
and it doesn't work for some reason. Not sure what is wrong actually but external service (CloudConvert) I am trying to send unable to recognize file correctly.
Here file
of type <class 'bytes'>
.
Tried to convert it to BytesIo
or BufferedReader
as suggested here without luck.
Could someone help me to post
file taken from bytes array with requests.request
?