Uploading file from file object with PyCurl
Posted
by Tom
on Stack Overflow
See other posts from Stack Overflow
or by Tom
Published on 2010-05-19T06:47:27Z
Indexed on
2010/05/19
6:50 UTC
Read the original article
Hit count: 434
I'm attempting to upload a file like this:
import pycurl
c = pycurl.Curl()
values = [
("name", "tom"),
("image", (pycurl.FORM_FILE, "tom.png"))
]
c.setopt(c.URL, "http://upload.com/submit")
c.setopt(c.HTTPPOST, values)
c.perform()
c.close()
This works fine. However, this only works if the file is local. If I was to fetch the image such that:
import urllib2
resp = urllib2.urlopen("http://upload.com/people/tom.png")
How would I pass resp.fp as a file object instead of writing it to a file and passing the filename? Is this possible?
© Stack Overflow or respective owner