• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/document/googlehandler.php
  • Класс: BitrixDiskDocumentGoogleHandler
  • Вызов: GoogleHandler::downloadFile
public function downloadFile(FileData $fileData)
{
	if(!$this->checkRequiredInputParams($fileData->toArray(), array(
		'id', 'mimeType', 'src',
	)))
	{
		return null;
	}

	$accessToken = $this->getAccessToken();

	$fileMetaData = $this->getFileMetadataInternal($fileData);
	if($fileMetaData === null)
	{
		$this->errorCollection[] = new Error(
			'Could not decode response as json', self::ERROR_BAD_JSON
		);
		return null;
	}
	$link = $this->getDownloadUrl($fileData, $fileMetaData);
	if(!$link)
	{
		$this->errorCollection[] = new Error(
			'Could not get link for download', self::ERROR_BAD_JSON
		);
		return null;
	}

	@set_time_limit(0);
	$http = new HttpClient(array(
		'socketTimeout' => 10,
		'streamTimeout' => 30,
		'version' => HttpClient::HTTP_1_1,
	));
	$http->setHeader('Authorization', "Bearer {$accessToken}");

	if($http->download($link, $fileData->getSrc()) === false)
	{
		$errorString = implode('; ', array_keys($http->getError()));
		$this->errorCollection[] = new Error(
			$errorString, self::ERROR_HTTP_DOWNLOAD_FILE
		);
		return null;
	}

	if (!$this->checkHttpResponse($http))
	{
		return null;
	}

	//$file['title'] = BaseComponent::convertFromUtf8($file['title']);
	$this->recoverExtensionInName($fileMetaData['name'], $fileData->getMimeType());
	$fileData->setName($fileMetaData['name']);

	return $fileData;
}