Я пытаюсь установить пользовательский эскиз через API, как только видео загружено через Data API V3.
Я получаю следующую ошибку:
Error calling PUT https://www.googleapis.com/upload/youtube/v3/thumbnails/set?videoId=[VIDEOID]&key=[KEY]&uploadType=resumable&upload_id=[UPLOADID]: (400) Invalid request. The number of bytes uploaded is required to be equal or greater than 262144, except for the final request (it's recommended to be the exact multiple of 262144). The received request contained 8192 bytes, which does not meet this requirement.
Загруженный эскизудовлетворяет всем требованиям, таким как * Соотношение сторон 16: 9 * Размер 1280 * 720 * Тип изображения png
$thumbnailFile = $thumbnailFile;
$client = new Google_Client();
$youtube = new Google_Service_YouTube($client);
$client->setAccessToken($accessToken);
$io = new Google_IO_Stream($client);
$io->setTimeout(180);
if ($client->getAccessToken()) {
$imagePath = $thumbnailFile;
$headers = get_headers($imagePath, 1);
$file_size= $headers["Content-Length"];
$mime_type = null;
if($headers['Content-Type'] == 'image/png' || $headers['Content-Type'] == 'image/jpeg'){
$mime_type = $headers['Content-Type'];
}
$chunkSizeBytes = 1 * 1024 * 100;
$client->setDefer(true);
$params = array('videoId' => $videoId);
$setRequest = $youtube->thumbnails->set($videoId);
$media = new Google_Http_MediaFileUpload(
$client,
$setRequest,
$mime_type,
$file_size,
true,
false
);
$media->setFileSize($file_size);
$status = false;
$handle = fopen($imagePath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
$client->setDefer(false);
$status['code'] = 1;
$status['message'] = 'Thumbnail uploaded successfully';