Post blob using Guzzle

Is it possible to host a blob using Guzzle? The only methods I could find were using @filename to upload a local file. The file is stored as a blob in the MySQL database, and I would like to upload it to the api as a message field without redundantly saving the blob to disk (and the rights / path issues that come with it), downloading @filename, and then disconnecting the file. Here is the code that I have that works for everything except 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 is to replace existing cURL code with Guzzle:

'file' => "@".$localfile.";type=".mime_content_type($localfile)
+4
source share
1 answer

I have found a solution. Hope 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])
+2
source

All Articles