From b1112924b6f80bbdc03dce4e092031a40b3d3b06 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 25 Feb 2026 17:22:51 +0530 Subject: [PATCH] GWM : endorsement file preview api --- app/Config/Routes.php | 1 + app/Controllers/EndorsementController.php | 41 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 26e41a0..388edbe 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -665,6 +665,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) { $routes->get("api/policy/PolicyFilePath", "PolicyController::PolicyFilePath"); + $routes->get("api/endorsement/EndorsementFilePath", "EndorsementController::EndorsementFilePath"); $routes->group('test', [ ], function ($routes) { diff --git a/app/Controllers/EndorsementController.php b/app/Controllers/EndorsementController.php index d1ac674..e455474 100644 --- a/app/Controllers/EndorsementController.php +++ b/app/Controllers/EndorsementController.php @@ -559,6 +559,47 @@ class EndorsementController extends ResourceController } } + public function EndorsementFilePath() + { + try { + $endorsementId = $this->request->getGet('endorsement_id'); + + if (!$endorsementId || !$fileType) { + return $this->respond(['status' => 'failed','code' => 400,'data' => 'endorsement_id is required'], 200); + } + + // Fetch record from DB + $fileRecord = $this->EndorsementModel->where('is_active', 1)->find((int)$endorsementId); + + if (!$fileRecord || empty($fileRecord['endorsement_file_name'])) { + return $this->respond([ 'status' => 'failed','code' => 404,'data' => 'File not found in database'], 200); + } + + $filePath = WRITEPATH . "uploads/endorsement/" . $fileRecord['endorsement_file_name']; + $publicUrl = base_url("uploads/endorsement/" . $fileRecord['endorsement_file_name']); + + if (!file_exists($filePath)) { + return $this->respond(['status' => 'failed','code' => 404,'data' => 'File missing on server'], 200); + } + + + // return $this->respond(['status' => 'success', 'code' => 200, 'data' => $publicUrl ], 200); + + // Detect the file mime type + $mime = mime_content_type($filePath); + + // Stream file to browser / Flutter + return $this->response + ->setHeader('Content-Type', $mime) + ->setHeader('Content-Disposition', 'inline; filename="' . $fileRecord[$fileColumn] . '"') + ->setBody(file_get_contents($filePath)); + + + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'message' => $e->getMessage() ], 500); + } + } +