guzzle 4: problem with addFile

140 views
Skip to first unread message

George Casinder

unread,
Jul 9, 2014, 12:30:29 PM7/9/14
to guz...@googlegroups.com
Hi,

I'm trying to POST multipart/form-data files.

I'm using:

$client = new GuzzleHttp\Client();

$request = $client->createRequest('POST', 'https://localhost/1/files/', ['json' => ['id' => 'dc51bfe4-92af-483d-80c4-f2da4cafa723'], 'cookies' => true]);

$request->getBody()->addFile(new PostFile('a.pdf', fopen('a.pdf', 'rb')));
$response = $this->client->send($request);

I'm getting this error:
Fatal error: Call to undefined method GuzzleHttp\Stream\Stream::addFile()


The same happens if I replace addFile with addPostFile.

Why is this happening? Which call should I be using?

Michael

unread,
Jul 14, 2014, 11:58:31 PM7/14/14
to guz...@googlegroups.com
You can't use the 'json' request option and create a multipart/form-data POST request. You need to pass an array in to the 'body' request option for this to work correctly.
Reply all
Reply to author
Forward
0 new messages