nextcloud/server · error · OCP\AppFramework\OCS\OCSBadRequestException

Direct download only works for files

Error message

Direct download only works for files

What it means

Error "Direct download only works for files" thrown in nextcloud/server.

Source

Thrown at apps/dav/lib/Controller/DirectController.php:79

	public function getUrl(int $fileId, int $expirationTime = 60 * 60 * 8): DataResponse {
		if (!$this->shareManager->shareApiAllowLinks()) {
			throw new OCSForbiddenException('Creating direct links is disabled');
		}

		$userFolder = $this->rootFolder->getUserFolder($this->userId);

		$file = $userFolder->getFirstNodeById($fileId);

		if (!$file) {
			throw new OCSNotFoundException();
		}

		if ($expirationTime <= 0 || $expirationTime > (60 * 60 * 24)) {
			throw new OCSBadRequestException('Expiration time should be greater than 0 and less than or equal to ' . (60 * 60 * 24));
		}

		if (!($file instanceof File)) {
			throw new OCSBadRequestException('Direct download only works for files');
		}

		$event = new BeforeDirectFileDownloadEvent($userFolder->getRelativePath($file->getPath()));
		$this->eventDispatcher->dispatchTyped($event);

		if ($event->isSuccessful() === false) {
			throw new OCSForbiddenException('Permission denied to download file');
		}

		//TODO: at some point we should use the directdownlaod function of storages
		$direct = new Direct();
		$direct->setUserId($this->userId);
		$direct->setFileId($fileId);

		$token = $this->random->generate(60, ISecureRandom::CHAR_ALPHANUMERIC);
		$direct->setToken($token);
		$direct->setExpiration($this->timeFactory->getTime() + $expirationTime);

View on GitHub (pinned to ecdeb153ff)

When it happens

Trigger: Thrown at apps/dav/lib/Controller/DirectController.php:79 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of nextcloud/server@ecdeb153ff (2026-08-17). Data as JSON: /api/errors/71e5f555c086b4c2. Report an issue: GitHub.