ixudra

Sending file using Guzzle

Posted 6 months ago by ixudra

I'm trying to transform a postman request into Guzzle. Postman works fine, Guzzle is a nightmare. Probably just a minor detail but I can't seem to figure it out. Any help is appreciated.

The postman request: Request

My request so far (not working)

            $response = $this->client->post(
                '/api/whitelabel/images', [
                    'headers' => [
                        'Accept'                => 'application/json',
                        'Content-Type'          => 'multipart/form-data',
                        'Authorization'         => 'Bearer '. $userToken,
                    ],
                    'multipart' => [
                        [
                            'name'     => 'myFile',
                            'contents' => file_get_contents($media->getPath()),
                        ],
                    ],
                ],
            );

Path to file is correct

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.