How to upload pdf file through guzzle http client in php laravel 8

  guzzle, laravel-8, php

How to pass pdf file through http client in php laravel 8? I need to get a pdf file from the user and upload it to a 3rd party service. I am doing the below:

$file = $request->file('pdf');
$response = Http::withOptions([
            'ssl_key' => $pemPath,
            'cert' => $crtPath
        ])->accept('application/json')
        ->contentType('application/json')
        ->attach('file',file_get_contents($file))
        ->post('https://domainname.com/api/client/session/');

It keeps give me unsupported media type!

Source: Ask PHP

LEAVE A COMMENT