I am trying to post image content as a parameter of the multiform request. The following code works.
$read_image = base64_encode(file_get_contents('Large.jpg'));
$client = new Client(['debug' => true ,'handler' => $stack,]);
$request = $client->Request(
'POST',
'https://mylandoapp.lndo.site/testdrive/post',
[
'multipart' =>
[
[
'name' => 'image',
'contents' => $read_image,
],
],
]
);
I am able to get the value using following code.
$data =$request->request->all();
$my_image = $data[$image];
When I try to add the file name, the image content is an empty array.
$request = $client->Request(
'POST',
'https://mylandoapp.lndo.site/testdrive/post',
[
'multipart' =>
[
[
'name' => 'image',
'contents' => $read_image,
'filename' => 'custom_filename.txt',
],
],
]);
How can I pass file name a well as file content using multiform post request?
Could be trivial, but first check that is actually a Guzzle issue and not a php memory limit issue. Base64 encoding a "Large.jpg" will triple the string length of $read_image. Check the php error log to see if your not running out of buffer length. I would try with a smaller JPEG first.