From 8ba3c2f2bdfef3900d0b11a3ca1c0606a7e80327 Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Fri, 30 Jan 2026 15:49:44 +0530 Subject: [PATCH] send doc has base64 --- .../controller/GuestDocuments.kt | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/android/trisolarisserver/controller/GuestDocuments.kt b/src/main/kotlin/com/android/trisolarisserver/controller/GuestDocuments.kt index 6b21c8a..06de4b1 100644 --- a/src/main/kotlin/com/android/trisolarisserver/controller/GuestDocuments.kt +++ b/src/main/kotlin/com/android/trisolarisserver/controller/GuestDocuments.kt @@ -27,6 +27,7 @@ import java.time.OffsetDateTime import java.nio.file.Files import java.nio.file.Paths import java.util.UUID +import java.util.Base64 @RestController @RequestMapping("/properties/{propertyId}/guests/{guestId}/documents") @@ -141,9 +142,7 @@ class GuestDocuments( extractionQueue.enqueue { val document = guestDocumentRepo.findById(documentId).orElse(null) ?: return@enqueue try { - val token = tokenService.createToken(document.id.toString()) - val imageUrl = - "${publicBaseUrl}/properties/$propertyId/guests/$guestId/documents/${document.id}/file?token=$token" + val imageUrl = buildImageDataUrl(document) ?: return@enqueue val results = linkedMapOf() results["hasAadhar"] = llamaClient.ask(imageUrl, "CONTAINS AADHAAR? Answer YES or NO only.") @@ -201,6 +200,24 @@ class GuestDocuments( } } + private fun buildImageDataUrl(document: GuestDocument): String? { + val contentType = document.contentType?.trim()?.lowercase() + if (contentType == null || !contentType.startsWith("image/")) { + return null + } + val path = Paths.get(document.storagePath) + if (!Files.exists(path)) { + return null + } + return try { + val bytes = Files.readAllBytes(path) + val encoded = Base64.getEncoder().encodeToString(bytes) + "data:$contentType;base64,$encoded" + } catch (_: Exception) { + null + } + } + } data class GuestDocumentResponse(