Capturing filename with python requests toolbelt -
i'm using python requests-toolbelt post large audio files. using requests post file so:
files = {'file': open("test.mp3", "rb")} audio_headers = {'authorization': 'bearer ' + token} add_file = requests.post(file_url, headers=audio_headers, files=files)
that grabbed file , added filename filename field, didn't work large files.
so switched posting files requests-toolbelt multipartencoder so:
files = multipartencoder({'file': open(file, "rb")}) audio_headers = {'authorization': 'bearer ' + token, 'content-type': 'audio/mpeg'} add_file = requests.post(file_url, headers=headers, data=files)
in scenario file created, filename isn't captured.
i tried defining files this:
files = multipartencoder({'file': file, open(file, "rb"), 'audio/mpeg')})
any idea how pass file name?
turns out needed follow example exactly...
files = multipartencoder(fields={'file': (file, open(file, "rb"), 'audio/mpeg')}) audio_headers = {'authorization': 'bearer ' + token, 'content-type': files.content_type} add_file = requests.post(file_url, headers=audio_headers, data=files)
totally works now.
Comments
Post a Comment