WYSIWYG

http://kufli.blogspot.com
http://github.com/karthik20522

Sunday, January 15, 2012

Face.com Post image - Local File - Face Detect

Face.com has two ways of accessing it’s API. One way is a simple Http GET, for example:

http://api.face.com/faces/detect.json?api_key={YOURAPIKEY}&api_secret={YOURSECRETKEY}&urls=http://farm3.static.flickr.com/2566/3896283279_0209be7a67.jpg

and the second way is to use Http POST to url [http://api.face.com/faces/detect.json]. In the GET request, you have to provide the URL of the image and in the POST request you can post image from your local machine. Unfortunately the examples on Face.com is quite vague. The example that they provided is like the following:

Content-Type: multipart/form-data; boundary=nonRelevantString
Content-Length: 104687
-----------------------------nonRelevantString
Content-Disposition: form-data; name="api_key"
4b4b4c6d54c37
-----------------------------nonRelevantString
Content-Disposition: form-data; name="api_secret"
sfhs8fj948fj29
-----------------------------nonRelevantString
Content-Disposition: form-data; filename="image.jpg"
Content-Type: image/jpeg
<>


Looking at the above example, it provides no information on how the post parameters should be constructed. Some of the examples that I came across was building the above text and post this as part of request header like the following example:

http://developers.face.com/forums/post2315.html#p2315

Bummer!

The basic idea of Face.com POST request is to post a multipart form with fields like “api_key”, “api_Secret” and “filename”. Following is a much cleaner code to post an image to face.com for face detection.



that “fileToUpload” is a input of type “File” like the following:



For those who are not aware of FormData, it’s a HTML5 element to build form object.

Labels: ,