user2266621 user2266621 - 4 months ago 6x
PHP Question

POST mime type using curl

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


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).