title: Laravel/Guzzle - POST binary file content
body: <p>I am trying to do a simple POST request to a 3rd party API. The API accepts a file as a BODY parameter. Specifically, the file content must be binary:</p>
  <p><a href="https://i.stack.imgur.com/F5egV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F5egV.png" alt="enter image description here" /></a></p>
  <p>I have successfully posted to this 3rd party API using Postman, with below body configuration:</p>
  <p><a href="https://i.stack.imgur.com/qH407.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qH407.png" alt="enter image description here" /></a></p>
  <p>When uploading the file, I am using Laravel. This is the code:</p>
  <pre class="lang-php prettyprint-override"><code>//$document is a class of &quot;UploadedFile&quot;
  $tempfile = Storage::disk('local')-&gt;putFile('/temp', $document);
  </code></pre>
  <p>I am then simply trying to post this file using Guzzle:</p>
  <pre class="lang-php prettyprint-override"><code>use Illuminate\Support\Facades\Http;
  
  $filepath = storage_path('app/' . $tempfile);
  $post = Http::attach('file', file_get_contents($tempfile), 'myfile.pdf')-&gt;post('example.org')-&gt;json());
  </code></pre>
  <p>However, the 3rd party API does not recognize this as a PDF file:</p>
  <blockquote>
  <p>Content type must be one of application/vnd.hypatos.ocr+json application/pdf image/tiff image/jpeg image/png text/xml application/xml</p>
  </blockquote>
  <p>What am I doing wrong compared to the request I am sending in Postman? It is the exact same file I am trying to post to the API.</p>