• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/document/office365handler.php
  • Класс: BitrixDiskDocumentOffice365Handler
  • Вызов: Office365Handler::getDataForViewFile
public function getDataForViewFile(FileData $fileData)
{
	$fileData = $this->createFileInternal($fileData);
	if($fileData === null)
	{
		return null;
	}

	$http = new HttpClient([
		'redirect' => false,
		'socketTimeout' => 10,
		'streamTimeout' => 30,
		'version' => HttpClient::HTTP_1_1,
	]);

	$http->setHeader('Content-Type', 'application/json; charset=UTF-8');
	$http->setHeader('Authorization', "bearer {$this->getAccessToken()}");

	if ($http->post($this->getApiUrlRoot() . "/drive/items/{$fileData->getId()}/preview") === false)
	{
		$errorString = implode('; ', array_keys($http->getError()));
		$this->errorCollection[] = new Error($errorString, self::ERROR_SHARED_EMBED_LINK);

		return null;
	}

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

	$responseData = Json::decode($http->getResult());
	if ($responseData === null)
	{
		$this->errorCollection[] = new Error('Could not decode response as json', self::ERROR_BAD_JSON);

		return null;
	}

	if (empty($responseData['getUrl']))
	{
		$this->errorCollection[] = new Error('Could not find getUrl in response', self::ERROR_SHARED_EMBED_LINK);

		return null;
	}

	$fileData->setLinkInService($responseData['getUrl']);
	ShowSession::register($this, $fileData, $this->errorCollection);

	return [
		'id' => $fileData->getId(),
		'viewUrl' => $responseData['getUrl'],
		'neededDelete' => true,
		'neededCheckView' => false,
	];
}