Reputation: 25094
I want to set the name of a file I'm uploading via requests module.
files = {'filename': open('myfileXXAAAZZZD','rb')}
r = requests.post("http://127.0.0.1:5000/", files=files)
It is possible with curl but don't know if requests support's this:
Upvotes: 10
Views: 11016
Reputation: 73470
As stated in the docs, the values of the files
dict can be tuples with filename and content as the first of possibly more elements. So something like
files = {'fieldname': ('filename.any', open('myfileXXAAAZZZD','rb').read())}
should do the trick.
Upvotes: 22