• Модуль: rpa
  • Путь к файлу: ~/bitrix/modules/rpa/lib/controller/comment.php
  • Класс: BitrixRpaControllerComment
  • Вызов: Comment::uploadFile
protected function uploadFile($fileContent): ?int
{
	if(empty($fileContent))
	{
		return null;
	}

	$fileArray = CRestUtil::saveFile($fileContent);
	if(!$fileArray)
	{
		$this->addError(new Error(Loc::getMessage('RPA_CONTROLLER_COULD_NOT_UPLOAD_FILE_ERROR')));
		return null;
	}

	$userId = Driver::getInstance()->getUserId();
	$storage = BitrixDiskDriver::getInstance()->addUserStorage($userId);
	if($storage)
	{
		$folder = $storage->getFolderForUploadedFiles();
		if($folder)
		{
			$file = $folder->uploadFile($fileArray, [
				'CREATED_BY' => $userId,
				'MODULE_ID' => Driver::MODULE_ID,
			], [], true);
			if($file)
			{
				return $file->getId();
			}

			$this->addErrors($folder->getErrors());
		}
	}

	return null;
}