Sending file using Guzzle

Viewed 378

I have to send a file using Guzzle, however, it's not sending correctly.

If I try to send those using a Curl, it works fine, but I can't make it works using Guzzle.

curl -X PATCH url/update_cv -H 'Authorization: Bearer XX' -H 'content-type: multipart/form-data;' -F 'candidate[cv]=@cv.pdf'

I've tried many ways to make it works using Guzzle, the closest that I got was using this code:

$client->request('PATCH', $url, [
  'headers' => $headers,
  'multipart' => [
    [
      'name' => $cv['name'],
      'contents' => $cv['content'],
    ],
  ],
]);

Has someone got an idea?

1 Answers

This is the correct way to send it:

$client->request(
                'PATCH',
                $url,
                [
                    'multipart' => [
                        [
                            'name' => 'candidate[cv]',
                            'contents' => $cv['content'],
                            'filename' => $cv['name'],
                        ],
                    ],
                ]
            );

Related