- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/document/onedrivehandler.php
- Класс: BitrixDiskDocumentOneDriveHandler
- Вызов: OneDriveHandler::createFileBySimpleUpload
protected function createFileBySimpleUpload(FileData $fileData)
{
$http = new HttpClient(array(
'redirect' => false,
'socketTimeout' => 10,
'streamTimeout' => 30,
'version' => HttpClient::HTTP_1_1,
));
$http->setHeader('Authorization', "bearer {$this->getAccessToken()}");
$http->setHeader('Content-type', $fileData->getMimeType());
if (
$http->query(
'PUT',
$this->getUploadPath($fileData) . 'content?' . http_build_query(array('@name.conflictBehavior' => 'rename')),
IOFile::getFileContents(IOPath::convertPhysicalToLogical($fileData->getSrc()))
) === false
)
{
$errorString = implode('; ', array_keys($http->getError()));
$this->errorCollection->add(array(
new Error($errorString, self::ERROR_HTTP_FILE_INTERNAL)
));
return null;
}
if (!$this->checkHttpResponse($http))
{
return null;
}
$finalOutput = Json::decode($http->getResult());
if ($finalOutput === null)
{
$this->errorCollection->add(array(
new Error('Could not decode response as json', self::ERROR_BAD_JSON)
));
return null;
}
$fileData
->setId($finalOutput['id'])
->setLinkInService($finalOutput['webUrl'])
->setMetaData($this->normalizeMetadata($finalOutput))
;
return $fileData;
}