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

	$fileId = $this->getForApiDecodedId($fileData->getId());

	$http = new HttpClient(array(
		'socketTimeout' => 10,
		'streamTimeout' => 30,
		'version' => HttpClient::HTTP_1_1,
	));
	$http->setHeader('Content-Type', 'application/json; charset=UTF-8');
	$http->setHeader('Authorization', "OAuth {$this->getAccessToken()}");

	if($http->get(self::API_URL_V1 . "/resources/download?path={$fileId}") === false)
	{
		$errorString = implode('; ', array_keys($http->getError()));
		$this->errorCollection->add(array(
			new Error($errorString, self::ERROR_HTTP_GET_METADATA)
		));
		return null;
	}

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

	$downloadData = Json::decode($http->getResult());
	if($downloadData === null || empty($downloadData['href']))
	{
		$this->errorCollection->add(array(
			new Error('Could not decode response as json', self::ERROR_BAD_JSON)
		));
		return null;
	}

	return $downloadData['href'];
}