PHP cURL Upload file without processing <p>I am trying to upload a file to a Rest API (Tableau Server Rest API) endpoint using PHP cURL.</p> <p>The <a href="http://onlinehelp.tableau.com/current/api/rest_api/en-us/help.htm#REST/rest_api_concepts_publish.htm%3FTocPath%3DConcepts%7C_____9" rel="nofollow">file upload procedure</a> exists of three steps:</p> <ol> <li>Initiate file upload (request upload token)</li> <li>Append file upload (upload file data)</li> <li>Publish resource (save the file)</li> </ol> <p>I was having issues with the server giving me a 500 status code on the second step. After contacting the support we figured out that the problem is most likely that the curl request seems to using the <code>-data</code> flag instead of the <a href="http://curl.haxx.se/docs/manpage.html#--data-binary" rel="nofollow"><code>--data-binary</code></a> flag which means some kind of encoding happens on the request body which should <strong>not</strong> be happening. This causes the server to respond with a 500 status code instead of an actual error message...</p> <p>I would like to know how i can make a cURL request with the <code>--data-binary</code> flag in PHP.</p> <p>Relevant sections of my current code:</p> <pre><code>// more settings $curl_opts[CURLOPT_CUSTOMREQUEST] = $method; $curl_opts[CURLOPT_RETURNTRANSFER] = true; $curl_opts[CURLOPT_HTTPHEADER] = $headers; $curl_opts[CURLOPT_POSTFIELDS] = $body; //more settings curl_setopt_array( $this-&gt;ch, $curl_opts ); $responseBody = curl_exec( $this-&gt;ch ); </code></pre> <p><code>$method</code> is "PUT", <code>$headers</code> contains an array with <code>Content-Type: multipart/mixed; boundary=boundary-string</code> and the <code>$body</code> is constructed like this:</p> <pre><code>$boundary = md5(date('r', time())); $body = "--$boundary\n"; $body .= "Content-Disposition: name='request_payload'\nContent-Type: text/xml\n\n"; $body .= "\n--$boundary\n"; $body .= "Content-Disposition: name='tableau_file'; filename='$fileName'\nContent-Type: application/octet-stream\n\n"; $body .= file_get_contents( $path ); $body .= "\n--$boundary--"; </code></pre> <p>Where the <code>$boundary</code> is the same as the boundary-string in the content-type header. i am aware this is a kinda/very messy way to construct my body, i am planning to use Mustache as soon as i can actually upload my files :S</p> <p>(i would like to mention that this is my first post here, please be gentle...)</p>