{"record":{"id":"eb374bc290cd5d31","repo":"BookStackApp/BookStack","slug":"errors-attachment-not-found","errorCode":null,"errorMessage":"errors.attachment_not_found","messagePattern":"errors\\.attachment_not_found","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"app/Uploads/Controllers/AttachmentController.php","lineNumber":222,"sourceCode":"\n        return response()->json(['message' => trans('entities.attachments_order_updated')]);\n    }\n\n    /**\n     * Get an attachment from storage.\n     *\n     * @throws FileNotFoundException\n     * @throws NotFoundException\n     */\n    public function get(Request $request, string $attachmentId)\n    {\n        /** @var Attachment $attachment */\n        $attachment = Attachment::query()->findOrFail($attachmentId);\n\n        try {\n            $page = $this->pageQueries->findVisibleByIdOrFail($attachment->uploaded_to);\n        } catch (NotFoundException $exception) {\n            throw new NotFoundException(trans('errors.attachment_not_found'));\n        }\n\n        if ($attachment->external) {\n            $url = (new UrlFilter($attachment->path))->clean();\n            return redirect($url);\n        }\n\n        $fileName = $attachment->getFileName();\n        $attachmentStream = $this->attachmentService->streamAttachmentFromStorage($attachment);\n        $attachmentSize = $this->attachmentService->getAttachmentFileSize($attachment);\n\n        if ($request->input('open') === 'true') {\n            return $this->createDownload()->streamedInline($attachmentStream, $fileName, $attachmentSize);\n        }\n\n        return $this->createDownload()->streamedDirectly($attachmentStream, $fileName, $attachmentSize);\n    }\n","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/app/Uploads/Controllers/AttachmentController.php#L204-L240","documentation":"NotFoundException rethrown in AttachmentController::get when findVisibleByIdOrFail cannot resolve the page the attachment is uploaded to, meaning the attachment exists but its parent page is not visible (deleted or restricted) to the requesting user. The translated errors.attachment_not_found message hides this detail.","triggerScenarios":"Thrown at app/Uploads/Controllers/AttachmentController.php:222 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the parent page still exists and has not been deleted","Check page/role permissions so the requesting user can view the parent page","If the attachment is orphaned, remove it or re-upload it to a valid page"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"18f8469a1c72f8cc8497e9372635e6dea5028071","analyzedAt":"2026-09-02T19:49:33.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}