Merged in feature/download-pdf (pull request #216)

retrieve document by id and tests

* working

* missing files
This commit is contained in:
Jay Brown
2026-03-17 17:06:57 +00:00
parent aafe7d5b5f
commit 2eff52877b
16 changed files with 1152 additions and 343 deletions
+39
View File
@@ -387,6 +387,44 @@ Retrieves enriched document details by ID, including metadata such as folder, fi
}
```
### `GET /document/{id}/download`
Streams the original uploaded document file directly from S3. The response Content-Type is auto-detected from the stored filename extension.
**Security**: Requires JWT authentication
**Path Parameters**:
- `id`: Document UUID (max 36 chars)
**Response** (`200`): Raw file bytes (streamed)
- `Content-Type`: Auto-detected from filename (e.g., `application/pdf`, `image/png`, `application/vnd.openxmlformats-officedocument.wordprocessingml.document`)
- `Content-Disposition`: `attachment; filename="<original_filename>"`
- `Content-Length`: File size in bytes
**Error Responses**:
- `400`: Invalid document ID format
- `401`: Missing or invalid JWT token
- `404`: Document not found or no S3 entry for the document
- `500`: S3 retrieval failure
**Example**:
```bash
curl -H "Authorization: Bearer <token>" \
-o report.pdf \
http://localhost:8080/document/019580df-ef65-7676-8de9-94435a93337a/download
```
**Notes**:
- No query parameters needed -- file type is automatically determined from the stored filename
- Response streams directly from S3, suitable for large files
- Returns 404 if the document has no stored file (e.g., legacy documents without S3 entries)
- Supports any file type without code changes (PDF, PNG, DOCX, CSV, etc.)
### `DELETE /document/{id}`
Permanently deletes a document and all dependent data: document entries, cleans (and their entries), text extractions (and their entries), field extractions (versions and array fields), labels, results, and result dependencies. Source documents in S3 are NOT deleted; their paths are logged and optionally returned.
@@ -1874,6 +1912,7 @@ The following table shows what data is passed to Permit.io for each protected en
| `POST` | `/client/{id}/document` | `client` | `post` | Upload document |
| `GET` | `/client/{id}/document` | `client` | `get` | List client documents |
| `GET` | `/document/{id}` | `document` | `get` | Get document details |
| `GET` | `/document/{id}/download` | `document` | `get` | Download document file |
| `DELETE` | `/document/{id}` | `document` | `delete` | Hard-delete document (super_admin only) |
| **Batch Document Operations** |
| `POST` | `/client/{id}/document/batch` | `client` | `post` | Upload batch (ZIP) |
+2 -1
View File
@@ -2,6 +2,7 @@
## Overview
This documentation provides comprehensive coverage of the DoczyAI Document Processing Platform - a cloud-native document processing system designed to extract structured information from documents.
## Documentation Structure
@@ -105,7 +106,7 @@ This documentation provides comprehensive coverage of the DoczyAI Document Proce
- **Monitoring**: Prometheus + OpenTelemetry
### 📊 Key Capabilities
- **Document Processing**: PDF upload, initialization, sync-gating, and cleaning
- **Document Processing**: PDF upload, download, initialization, sync-gating, and cleaning
- **Multi-tenant Support**: Isolated client environments
- **Document Organization**: Folders and labels for document management
- **Export Operations**: Structured data export in multiple formats
+7
View File
@@ -25,6 +25,7 @@ This document provides a comprehensive summary of all REST API endpoints availab
| /client/{id}/document/batch | GET, POST | DocumentsService |
| /client/{id}/document/batch/{batch_id} | GET | DocumentsService |
| /document/{id} | GET, DELETE | DocumentsService |
| /document/{id}/download | GET | DocumentsService |
| /documents/{documentId}/labels | GET, POST | LabelService |
| /labels/{labelName}/documents | GET | LabelService |
| /field-extractions | GET, POST | FieldExtractionService |
@@ -165,6 +166,12 @@ This document provides a comprehensive summary of all REST API endpoints availab
- `textRecord` (optional, default: false) - When true, includes full text extraction record
- Returns: `{id, client_id, hash, folder_id, filename, labels[], fields{}, text_record?}`
- **GET /document/{id}/download** - Download the original document file
- Streams file directly from S3 storage
- Content-Type auto-detected from stored filename extension
- Returns: Raw file bytes with `Content-Disposition: attachment` header
- Supports any file type (PDF, PNG, DOCX, CSV, etc.)
- **DELETE /document/{id}** - Hard-delete a document and all dependent data (super_admin only)
- Query Parameters:
- `verbose` (optional, default: false) - When true, returns S3 paths of orphaned source documents