Search code examples
phppostcurltypesmime

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


Solution

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