- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/document/onedrivehandler.php
- Класс: BitrixDiskDocumentOneDriveHandler
- Вызов: OneDriveHandler::downloadFileContent
private function downloadFileContent(FileData $fileData, $startRange = null, $chunkSize = null)
{
if(!$this->checkRequiredInputParams($fileData->toArray(), array(
'id', 'src',
)))
{
return null;
}
$accessToken = $this->getAccessToken();
@set_time_limit(0);
$http = new HttpClient(array(
'socketTimeout' => 10,
'streamTimeout' => 30,
'version' => HttpClient::HTTP_1_1,
));
$http->setHeader('Authorization', "bearer {$accessToken}");
if($startRange !== null && $chunkSize !== null)
{
$endRange = $startRange + $chunkSize - 1;
$http->setHeader('Range', "bytes={$startRange}-{$endRange}");
}
if($http->download($this->getApiUrlRoot() . "/drive/items/{$fileData->getId()}/content", $fileData->getSrc()) === false)
{
$errorString = implode('; ', array_keys($http->getError()));
$this->errorCollection->add(array(
new Error($errorString, self::ERROR_HTTP_DOWNLOAD_FILE)
));
return null;
}
if(!$this->checkHttpResponse($http))
{
return null;
}
$filename = $http->getHeaders()->getFilename();
if ($filename)
{
$fileData->setName($filename);
}
return $fileData;
}