WordPress api post image raw data without being blank in media library

I found a solution !

      file_put_contents($filepath, base64_decode($data));

      // Make sure the image exist
      if (!file_exists($filepath)){return;}

      // Load the image
      $file = file_get_contents($filepath);

      // Get the filename
      $filename = $image_name? $image_name : basename($filepath);

      // Initiate curl.
      $ch = curl_init();
      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt( $ch, CURLOPT_URL, $url .'/wp-json/wp/v2/media/' );
      curl_setopt( $ch, CURLOPT_POST, 1 );
      curl_setopt( $ch, CURLOPT_POSTFIELDS, $file );
      curl_setopt( $ch, CURLOPT_HTTPHEADER, [
          "Content-Disposition: form-data; filename=\"$filename\"",
          'Authorization: Bearer ' .$result_auth->access_token,
      ] );
      $result = curl_exec( $ch );
      curl_close( $ch );

      // Decode the response
      $api_response = json_decode($result);

      return $api_response;