不知道这是不是一个好方法。但我用curl解决了这个问题。
public function uploadFeaturedImage($post_id)
{
$api_id = $this->get_api_id($post_id);
$url = blog_transporter_build_api_url(\'posts/\' . $api_id . \'/photo\');
$image_url = get_the_post_thumbnail_url($post_id);
if (empty($image_url)) return false;
$image_id = get_post_thumbnail_id($post_id);
$mime_type = get_post_mime_type($image_id);
$data = array(\'file\' => new CURLFile(
$image_url,
$mime_type,
\'featured-image\'
));
$headers = array(\'Authorization: Bearer <token>\' , \'Content-Type: multipart/form-data\');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
return $response;
}