0

So I'm attempting to use an api called Sky Biometry, which is used for face detection and facial recognition. The api either accepts a url or a post as a MIME type. In this case I would like to directly post the picture to the api, here is what the documentation says:

"Note: in case where you want to POST images instead of specifying urls, request to the method must be formed as a MIME multi-part message sent using POST data. Each argument should be specified as a separate chunk of form data."

I've tried looking around for examples, but have yet to find any, if somebody could help a newbie out it would be greatly appreciated.

Sky Biometry Documentation

alex
  • 425
  • 4
  • 21
user2266621
  • 97
  • 1
  • 1
  • 7

2 Answers2

0

Multipart messages are actually standard POST enctype="multipart/form-data" requests. You can generate them quite simply with a simple form, or you can use cURL (as I suspect you are already doing) as follows:

curl_setopt($channel, CURLOPT_POSTFIELDS, array("myfile" => "@/path/to/my/image.png"));

cURL will automatically do the rest (convert your content-type and mime-type it).

Sébastien Renauld
  • 19,203
  • 2
  • 46
  • 66
  • Anybody finding this now, but unable to get it to work, check out https://stackoverflow.com/a/29122849/1166029 -- this method is deprecated as of PHP 5.5 – samson Jul 05 '17 at 19:21
0

This an example structure of posting values using curl,

$value1 = 'DATA 1;
$value2 = 'DATA 2';
$url = 'http://www.skybiometry.com/file/api/facedetection/example';
$fields = array(
                        'mimetype' => urlencode($value1),
                        'mimetype2' => urlencode($value2)
                );

//url-ify the data for the POST
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

Hope this might help you.

naveencgr8
  • 331
  • 1
  • 4
  • 13