I would like to upload a file from URL using Python requests.post
Would anyone guide me how to convert a file URL into binary data (multipart/form-data) for upload?
I have tried with these code but it return failed.
file = requests.get(file_url, stream=True)
file_upload = {
"name": file_name,
"uploadfile": file.content
}
headers = {
'Content-Type': 'multipart/form-data',
'Accept': 'application/json'
}
requests.post('{POST_URL}', files=file_upload, headers=headers)
POST_URL is external service and only support PDF file (string($binary)).
{
"name": string
"uploadfile": string($binary)
}
Thank you so much.