Upload Image Remotely from Rest API using JWT Authorization INVALID_AUTHORIZATION_HEADER_TOKEN_TYPE


Trying to upload images into my media gallery programatically from my local machine to webserver.

Using this function here to get the JWT token along with the
WordPress REST API Authentication plugin to initialize JWT:

function get_jwt_token_wp(): ?string {     $  request_url = 'https://example.com/wp-json/api/v1/token';      $  api = curl_init();      $  username = 'admin';     $  password = 'password';     //set the url, POST data     curl_setopt( $  api, CURLOPT_URL, $  request_url );     curl_setopt( $  api, CURLOPT_POST, 1 );     curl_setopt( $  api, CURLOPT_POSTFIELDS, "username=$  username&password=$  password" );     curl_setopt( $  api, CURLOPT_VERBOSE, 1);     curl_setopt( $  api, CURLOPT_RETURNTRANSFER, 1 );      $  server_output = curl_exec ($  api);     printr(curl_getinfo($  api));     if ($  server_output === false) {         die('Error getting JWT token on WordPress for API integration.');     }     $  server_output = json_decode($  server_output);      if ($  server_output === null && json_last_error() !== JSON_ERROR_NONE) {         die('Invalid response getting JWT token on WordPress for API integration.');     }      if (!empty($  server_output->jwt_token)) {         $  jwt_token = $  server_output->jwt_token;         curl_close ($  api);         return $  jwt_token;     } else {         die('Invalid response getting JWT token on WordPress for API integration.');     }     return null; } 

and this function to upload the image

function upload_image_wp( $  path ): array {     $  request_url = 'https://example.com/wp-json/wp/v2/media';      $  image = file_get_contents( $  path );     $  mime_type = mime_content_type( $  path );      $  api = curl_init();      $  username = 'admin';     $  password = 'password';      $  httpheader = array( 'Content-Type: ' . $  mime_type, 'Content-Disposition: attachment; filename="' . basename($  path) . '"', 'Authorization' => 'Bearer ' . WOO_JWT_KEY );      curl_setopt( $  api, CURLOPT_URL, $  request_url );     curl_setopt( $  api, CURLOPT_POST, 1 );     curl_setopt( $  api, CURLOPT_POSTFIELDS, $  image );     curl_setopt( $  api, CURLOPT_HTTPHEADER, $  httpheader );     curl_setopt( $  api, CURLOPT_VERBOSE, 1);     curl_setopt( $  api, CURLOPT_RETURNTRANSFER, 1 );     curl_setopt( $  api, CURLOPT_USERPWD, $  username . ':' . $  password );     $  result = curl_exec( $  api );     printr(curl_getinfo($  api));     curl_close( $  api );     return json_decode( $  result ); } 

with my headers looking something like this:

Array (     [0] => Content-Type: image/gif     [1] => Content-Disposition: attachment; filename="user_loggedin_avatar.gif"     [Authorization] => Bearer eyJhbGciOiJIU..................................... ) 

Is my format wrong? Am I doing something else wrong? I have never worked with JWT authentication before so this has all been new to me.

This is the error I am getting on the return of my call.

object(stdClass)[3]   public 'status' => string 'error' (length=5)   public 'error' => string 'INVALID_AUTHORIZATION_HEADER_TOKEN_TYPE' (length=39)   public 'code' => string '401' (length=3)   public 'error_description' => string 'Authorization header must be type of Bearer Token.' (length=50) 

Unfortunately google isn’t showing much of anything regarding why this error pops up, so I am a bit stuck. Any help greatly appreciated!