{"record":{"id":"71e5f555c086b4c2","repo":"nextcloud/server","slug":"direct-download-only-works-for-files","errorCode":null,"errorMessage":"Direct download only works for files","messagePattern":"Direct download only works for files","errorType":"exception","errorClass":"OCP\\AppFramework\\OCS\\OCSBadRequestException","httpStatus":400,"severity":"error","filePath":"apps/dav/lib/Controller/DirectController.php","lineNumber":79,"sourceCode":"\tpublic function getUrl(int $fileId, int $expirationTime = 60 * 60 * 8): DataResponse {\n\t\tif (!$this->shareManager->shareApiAllowLinks()) {\n\t\t\tthrow new OCSForbiddenException('Creating direct links is disabled');\n\t\t}\n\n\t\t$userFolder = $this->rootFolder->getUserFolder($this->userId);\n\n\t\t$file = $userFolder->getFirstNodeById($fileId);\n\n\t\tif (!$file) {\n\t\t\tthrow new OCSNotFoundException();\n\t\t}\n\n\t\tif ($expirationTime <= 0 || $expirationTime > (60 * 60 * 24)) {\n\t\t\tthrow new OCSBadRequestException('Expiration time should be greater than 0 and less than or equal to ' . (60 * 60 * 24));\n\t\t}\n\n\t\tif (!($file instanceof File)) {\n\t\t\tthrow new OCSBadRequestException('Direct download only works for files');\n\t\t}\n\n\t\t$event = new BeforeDirectFileDownloadEvent($userFolder->getRelativePath($file->getPath()));\n\t\t$this->eventDispatcher->dispatchTyped($event);\n\n\t\tif ($event->isSuccessful() === false) {\n\t\t\tthrow new OCSForbiddenException('Permission denied to download file');\n\t\t}\n\n\t\t//TODO: at some point we should use the directdownlaod function of storages\n\t\t$direct = new Direct();\n\t\t$direct->setUserId($this->userId);\n\t\t$direct->setFileId($fileId);\n\n\t\t$token = $this->random->generate(60, ISecureRandom::CHAR_ALPHANUMERIC);\n\t\t$direct->setToken($token);\n\t\t$direct->setExpiration($this->timeFactory->getTime() + $expirationTime);\n","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/nextcloud/server/blob/ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3/apps/dav/lib/Controller/DirectController.php#L61-L97","documentation":"Error \"Direct download only works for files\" thrown in nextcloud/server.","triggerScenarios":"Thrown at apps/dav/lib/Controller/DirectController.php:79 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3","analyzedAt":"2026-08-17T01:36:13.386Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}