Rewrite curl with Guzzle (File Upload) - PHP Rewrite curl with Guzzle (File Upload) - PHP curl curl

Rewrite curl with Guzzle (File Upload) - PHP


It can be OK to use multipart, but the server has to handle it correctly. It is a different request-body whether you use it or not.

It is often used in HTML forms with (multiple) file uploads. Files are named (thus the meta infos), so there can be multiple files. There could also be normal form fields (text) along the files. You can probably find a better explanation of it by searching, just wanted to give a brief explanation.

And it seems in your case the server doesn't handle the multipart form data differently from a "binary post", so it saves it all, including the meta info.

Use body to pass a raw body and produce an identical request to your curl with Guzzle:

$urlAttachments = $this->params['base_url']."/api/v2/uploads.json?filename=".$file->getClientOriginalName();$opts = [    // auth    'body' => fopen($file->getRealPath(), "r"),    'headers' => ['Content-Type' => 'application/binary'],];$client = new \GuzzleHttp\Client();$response = $client->request('POST', $urlAttachments, $opts);