Search code examples
pythonapihttppostmime

Face.com API upload image from python


I'm trying to upload an image to the Face.com API. It either takes a url to an image, or images can be uploaded directly. Their website says:

A requests that uploads a photo must be formed as a MIME multi-part message sent using POST data. Each argument, including the raw image data, should be specified as a separate chunk of form data.

Problem is, I don't know exactly what that means. Right now my code looks like this:

import urllib
import json

apikey = "[redacted]"
secret = "[redacted]"

img = raw_input("Enter the URL of an image: ");

url = "http://api.face.com/faces/detect.json?api_key=" + apikey + "&api_secret=" + secret + "&urls=" + urllib.quote(img) + "&attributes=all"
data = json.loads(urllib.urlopen(url).read())

How can I convert this to work with a locally stored image?


Solution

  • The easiest way to upload photo in Python to face.com API is just using the Python Client Library that can be downloaded form http://developers.face.com/download/.

    You got 2 there. Both support uploading by passing filename to the detected method (as a different param than the urls).