Is it possible to post a blob using Guzzle? The only methods I've been able to find are using @filename to upload a local file. The file is stored as a blob in a MySQL database and I would like to upload it to an api as a post field without the redundancy of saving the blob to disk (and the permissions/path issues that come with it), uploading @filename, and then unlinking the file. Here is the code I have that is working for everything but the blob. I need the 'file' field to save the data as a blob.
$data = array(
'first_name' => $fname,
'last_name' => $lname,
'email' => $email,
'partner_key' => 'qwerty',
'secret_key' => 'qwerty',
'file' => $fileblob
);
$curl = new \GuzzleHttp\Client();
return $curl->post('https://www.api.com',['verify'=>false,'body'=>$data])
The goal being to replace the existing cURL code using Guzzle:
'file' => "@".$localfile.";type=".mime_content_type($localfile)
I found the solution. Hopefully this helps others in the future:
$data = array(
'first_name' => $fname,
'last_name' => $lname,
'email' => $email,
'partner_key' => 'qwerty',
'secret_key' => 'qwerty',
'file' => new \GuzzleHttp\Post\PostFile('filename', $fileblob)
);
$curl = new \GuzzleHttp\Client();
return $curl->post('https://www.api.com',['verify'=>false,'body'=>$data])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With