title: POST binary file using curl
body: <p>I have a basic upload form which I would like to emulate using cURL.</p>
  
  <pre><code>&lt;?php
  $params = array(
      'api_key' =&gt; $api_key,
      'api_secret' =&gt; $api_secret,
      'urls' =&gt; null,
      'uids' =&gt; 'all',
      'detector' =&gt; 'Aggressive',
      'namespace' =&gt; 'face.auth');
  
  $action = $url . '?' . http_build_query($params);
  ?&gt;
  
  &lt;form enctype="multipart/form-data" method="post" action="&lt;?php echo $action; ?&gt;"&gt;  
      &lt;input type="file" name="upload" id="upload"&gt;
      &lt;input type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I know how to post using cURL, but I'm not sure how to post the image data (this data is stored as binary data in a database, lets call it <code>$binary</code>). Passing <code>$binary</code> as shown below as a postfield does not work. I have seen some examples which place an <code>@</code> in front of the file name/path, and send that as a postfield. However, this does not appear to work for me (since I am dealing with binary data, not a file name/path).</p>
  
  <pre><code>$params = array(
      'api_key' =&gt; $api_key,
      'api_secret' =&gt; $api_secret,
      'urls' =&gt; null,
      'uids' =&gt; 'all',
      'detector' =&gt; 'Aggressive',
      'namespace' =&gt; 'face.auth',
      $binary);
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, 1);      
  curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $data = curl_exec($ch);
  curl_close($ch);
  
  var_dump($data);
  
  ?&gt;
  </code></pre>
  
  <p>I've also tried:</p>
  
  <pre><code>    $params = array(
              'api_key' =&gt; $api_key,
              'api_secret' =&gt; $api_secret,
              'urls' =&gt; null,
              'uids' =&gt; 'all',
              'detector' =&gt; 'Aggressive',
              'namespace' =&gt; 'face.auth');
  
  
  $action = $url . '?' . http_build_query($params);
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $action);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $binary);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $data = curl_exec($ch);
  curl_close($ch);
  </code></pre>
  
  <p>Any assistance would be appreciated.</p>