GWM : endorsement file preview api
This commit is contained in:
parent
70d828bca6
commit
b1112924b6
@ -665,6 +665,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
|||||||
|
|
||||||
|
|
||||||
$routes->get("api/policy/PolicyFilePath", "PolicyController::PolicyFilePath");
|
$routes->get("api/policy/PolicyFilePath", "PolicyController::PolicyFilePath");
|
||||||
|
$routes->get("api/endorsement/EndorsementFilePath", "EndorsementController::EndorsementFilePath");
|
||||||
|
|
||||||
$routes->group('test', [ ], function ($routes) {
|
$routes->group('test', [ ], function ($routes) {
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user