{"record":{"id":"9580e9ce9bb5f66f","repo":"nextcloud/server","slug":"permission-denied-to-download-file","errorCode":null,"errorMessage":"Permission denied to download file","messagePattern":"Permission denied to download file","errorType":"exception","errorClass":"OCP\\AppFramework\\OCS\\OCSForbiddenException","httpStatus":403,"severity":"error","filePath":"apps/dav/lib/Controller/DirectController.php","lineNumber":86,"sourceCode":"\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\n\t\t$this->mapper->insert($direct);\n\n\t\t$url = $this->urlGenerator->getAbsoluteURL('remote.php/direct/' . $token);\n\n\t\treturn new DataResponse([\n\t\t\t'url' => $url,\n\t\t]);","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/nextcloud/server/blob/ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3/apps/dav/lib/Controller/DirectController.php#L68-L104","documentation":"Error \"Permission denied to download file\" thrown in nextcloud/server.","triggerScenarios":"Thrown at apps/dav/lib/Controller/DirectController.php:86 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"}