Skip to main content

Lania Storage – Dokumentasi Teknis API

Dokumentasi komunikasi dengan service lania-storage: base URL, endpoint, payload, response, dan error code.


Base URL & Umum

  • Base URL: http(s)://<host>:<port>
    Default development: http://localhost:8090 (atur lewat env PORT).
  • Prefix API: Semua endpoint file di bawah prefix /api.
  • Health check: GET /health (tanpa prefix /api)
    Response: { "status": "ok", "timestamp": "<ISO>", "service": "lania-storage", "version": "1.0.0" }.
  • Content-Type:
    • Upload: multipart/form-data.
    • Response JSON: application/json.

Endpoint

MethodPathDeskripsi
POST/api/filesUpload file
GET/api/read/{path}Baca file (inline, e.g. tampil di browser)
GET/api/download/{path}Download file (attachment)
GET/api/pdf/{path}Baca file PDF (untuk PDF viewer, inline + range)
DELETE/api/files/{path}Hapus file (soft delete)

{path} = path file di storage (bisa nested), contoh: data-tenant/tenant-uuid/1234567890.pdf.
Gunakan path yang dikembalikan saat upload (data.file_path) untuk read/download/pdf/delete.
(Path di URL harus di-encode jika ada karakter khusus.)


1. Upload file – POST /api/files

Request

  • Content-Type: multipart/form-data
  • Body (form-data):
FieldTypeWajibDeskripsi
filefileYaSatu file (nama field bebas; disarankan file). Hanya file pertama yang diproses.
tenant_idstring (UUID)TidakTenant ID.
user_idstring (UUID)TidakUser ID.
is_publicboolean/stringTidaktrue / "true" = public. Default: false.
related_databasestringTidakNama database (e.g. lania_common, lania_sso).
related_tablestringTidakNama table yang dikaitkan.
related_idstringTidakID record terkait (UUID atau string).
related_servicestringTidakService key (e.g. master-data, producement).
descriptionstringTidakDeskripsi file.

Validasi:

  • Tipe file: png, jpg, jpeg, pdf, doc, docx, xls, xlsx, csv (validasi MIME + ekstensi).
  • Ukuran: Maksimal 5 MB (default). Bisa diubah lewat env FILE_SIZE_LIMIT_MB.
    Jika melebihi limit, request bisa ditolak oleh Multer sebelum sampai controller.

Response sukses – 201 Created

{
"message": "File uploaded successfully",
"data": {
"id": "uuid",
"file_name": "original-name.pdf",
"file_path": "data-tenant/<tenant-id>/<unique>.pdf",
"file_type": "pdf",
"file_size": 12345,
"mime_type": "application/pdf",
"description": null,
"is_public": false,
"related_database": null,
"related_table": null,
"related_id": null,
"related_service": null,
"created_at": "2025-02-20T00:00:00.000Z",
"updated_at": "2025-02-20T00:00:00.000Z"
}
}

Simpan data.file_path untuk dipakai di read / download / pdf / delete.

Response error (upload)

HTTPKondisiBody JSON
400Tidak ada file{ "message": "File is required", "status": 400 }
400Tipe file tidak diizinkan{ "message": "File type not allowed. Allowed types: png, jpg, jpeg, pdf, doc, docx, xls, xlsx, csv", "status": 400 }
400Ukuran file > limit{ "message": "File size exceeds maximum limit of 5MB", "status": 400 }
500Gagal upload (server/DB/storage){ "message": "Failed to upload file", "status": 500 }

Jika request melebihi limit ukuran di Multer, error bisa dikembalikan oleh global error handler (biasanya 413 atau 500, tergantung konfigurasi Multer).


2. Read file (inline) – GET /api/read/{path}

Menampilkan file di browser (inline).

Request

  • Method: GET
  • URL: /api/read/<file_path>
    Contoh: /api/read/data-tenant/abc-123/doc.pdf
    file_path = nilai file_path dari response upload (bisa nested; encode URL jika ada karakter khusus).

Response sukses – 200 OK

  • Body: Binary (isi file).
  • Headers:
    • Content-Type: MIME file (e.g. application/pdf, image/png).
    • Content-Disposition: inline; filename="...".
    • Content-Length: ukuran byte.

Response error

HTTPKondisiBody JSON
404Record tidak ada / path tidak ditemukan{ "message": "File not found", "status": 404 }
404Ada di DB tapi tidak ada di object storage{ "message": "File not found in object storage", "status": 404 }
404Ada di DB tapi tidak ada di disk (local){ "message": "File not found on disk", "status": 404 }
500Error server{ "message": "Internal server error", "status": 500 }

3. Download file – GET /api/download/{path}

Mengunduh file sebagai attachment.

Request

  • Method: GET
  • URL: /api/download/<file_path>
    Sama seperti read, gunakan file_path dari response upload.

Response sukses – 200 OK

  • Body: Binary (isi file).
  • Headers:
    • Content-Type: application/octet-stream.
    • Content-Disposition: attachment; filename="...".
    • Content-Length: ukuran byte.

Response error

Sama seperti Read file (404 / 500, body JSON seperti di atas).


4. Read PDF (viewer) – GET /api/pdf/{path}

Khusus PDF: inline + header yang mendukung PDF viewer (cache, range request).

Request

  • Method: GET
  • URL: /api/pdf/<file_path>
    Path harus mengarah ke file yang tipe PDF (validasi di backend).

Response sukses – 200 OK

  • Body: Binary (isi PDF).
  • Headers:
    • Content-Type: application/pdf.
    • Content-Disposition: inline; filename="...".
    • Content-Length, Cache-Control, Accept-Ranges (untuk range request).

Response error

HTTPKondisiBody JSON
400Bukan file PDF{ "message": "File is not a PDF", "status": 400 }
404File tidak ditemukan (DB / object storage / disk){ "message": "File not found" } atau "File not found in object storage" / "File not found on disk", "status": 404
500Error server{ "message": "Internal server error", "status": 500 }

5. Delete file – DELETE /api/files/{path}

Soft delete: record di DB di-mark deleted; file di object storage / disk dihapus (hard delete dari storage).

Request

  • Method: DELETE
  • URL: /api/files/<file_path>
    Gunakan file_path dari response upload.

Response sukses – 200 OK

{
"message": "File deleted successfully"
}

(Tidak ada field data.)

Response error

HTTPKondisiBody JSON
404File tidak ditemukan di DB{ "message": "File not found", "status": 404 }
500Error server{ "message": "Failed to delete file", "status": 500 }

Ringkasan error code

StatusArtiDipakai di
200OKDelete sukses; Read/Download/PDF mengembalikan binary.
201CreatedUpload sukses.
400Bad RequestUpload: no file, wrong type, file too large. PDF: not a PDF.
404Not FoundRead / Download / PDF / Delete: file tidak ada (DB / storage / disk).
500Internal Server ErrorKegagalan server (DB, storage, unexpected error).

Semua response error JSON memakai bentuk:

{
"message": "<pesan human-readable>",
"status": <http_status_code>
}

Di development, global error handler bisa menambah field stack pada response.


Contoh alur (service lain / frontend)

  1. Upload:
    POST /api/files dengan multipart/form-data (file + optional metadata).
    Simpan response.data.file_path.
  2. Tampil inline (gambar/PDF):
    GET /api/read/<file_path> atau untuk PDF: GET /api/pdf/<file_path>.
  3. Download:
    GET /api/download/<file_path>.
  4. Hapus:
    DELETE /api/files/<file_path>.

Path selalu nilai file_path dari response upload (bisa berisi slash, e.g. data-tenant/tenant-id/filename.pdf); encode untuk URL bila perlu.