Example #1
0
    def post_url(self,
                 url,
                 fields=None,
                 headers=None,
                 retries=3,
                 redirect=True):
        """
        Wrapper for performing POST with urlopen (see urlopen for more details).

        Supports an optional ``fields`` parameter of key/value strings AND
        key/filetuple. A filetuple is a (filename, data) tuple. For example:

        fields = {
            'foo': 'bar',
            'foofile': ('foofile.txt', 'contents of foofile'),
        }

        NOTE: If ``headers`` are supplied, the 'Content-Type' value will be
        overwritten because it depends on the dynamic random boundary string
        which is used to compose the body of the request.
        """
        body, content_type = encode_multipart_formdata(fields or {})

        headers = headers or {}
        headers.update({'Content-Type': content_type})

        return self.urlopen('POST',
                            url,
                            body,
                            headers=headers,
                            retries=retries,
                            redirect=redirect)
    def post_url(self, url, fields={}, headers={}, retries=3, redirect=True):
        """
        Wrapper for performing POST with urlopen (see urlopen for more details).

        Supports an optional ``fields`` parameter of key/value strings AND
        key/filetuple. A filetuple is a (filename, data) tuple. For example:

        fields = {
            'foo': 'bar',
            'foofile': ('foofile.txt', 'contents of foofile'),
        }

        NOTE: If ``headers`` are supplied, the 'Content-Type' value will be
        overwritten because it depends on the dynamic random boundary string
        which is used to compose the body of the request.
        """
        body, content_type = encode_multipart_formdata(fields)
        headers.update({'Content-Type': content_type})
        return self.urlopen('POST', url, body, headers=headers, retries=retries, redirect=redirect)
Example #3
0
def uploadImages(imageUrlFiles, prefix = "OpalFruit-"):
	params = {"method": "add"}
	imageObjects = []
	i = 0
	host="piximilar-rw.hackott.tineye.com"
	url="/rest/"
	port=80
	for imageFile in imageUrlFiles:
		buffer = StringIO.StringIO(imageFile.read());
		key = "images[" + str(i) + "]"
		i = i + 1
		filename = prefix + imageFile.geturl()[7:] # strip the http
		imageObjects.append((key , filename , buffer.getvalue()))
		print "Adding image " + filename
	postdata = filepost.encode_multipart_formdata(params, imageObjects)
	try:
		con = httplib.HTTPConnection(host, port)
		con.request("POST", url, postdata[1], headers={"Content-Type": postdata[0]})
		response = con.getresponse()
		print response.read()
	except Exception, e:
		print e
		pass