Explore documentation

Uploading Document Content

Storing and retrieving the actual bytes that back a clinical document

How Esus Stores Document Bytes

Esus does not expose the FHIR Binary resource. Instead, a dedicated file-storage service under /files stores the bytes, checks the file type against its content, scans it with an antivirus (when configured), and keeps it bound to your organization.

The FHIR resources then point to the file by URL (DocumentReference.content[].attachment.url, Media.content.url).

These endpoints are not FHIR resources: success and error bodies are plain JSON, not OperationOutcome. With an API key, they require the File.create, File.read and File.delete scopes.

Upload a File

POST /files/upload accepts a multipart/form-data body with a single file part. Maximum size is 50 MB. Uploads are rate-limited to 10 per user per minute; above that the API returns 429 with a Retry-After header.

curl -X POST https://api.esus.health/files/upload \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "file=@/path/to/document.pdf"

Response (200):

{
  "id": "b8f0c2d1-9e3a-4f5b-8c7d-1a2b3c4d5e6f",
  "key": "<org-id>/<random-hash>.pdf",
  "contentType": "application/pdf",
  "size": 384213,
  "url": "/files/b8f0c2d1-9e3a-4f5b-8c7d-1a2b3c4d5e6f"
}
  • id is the file’s canonical UUID — use it for download and delete.
  • contentType is the type detected from the bytes, not the one your client declared.
  • url is the authenticated relative path /files/{id}. Add the API origin for attachment.url. key identifies the object in storage.

Checks performed before storing:

  1. Type detection — the file must be one of the allowed formats, and its extension and declared MIME type must match the detected bytes. Otherwise: 415 with { "error": "Unsupported or mismatched file type", "detail": "..." }.
  2. Antivirus scan — when ClamAV is configured, infected files are rejected with 422 ({ "error": "File rejected by antivirus scan" }).
  3. Tenant binding — the file is recorded under the caller’s organization.

Allowed formats: PDF, JPEG, PNG, GIF, WebP, DICOM, ZIP-based Office files (.zip, .docx, .xlsx, .pptx), legacy Office files (.doc, .xls, .ppt), and plain text (.txt, .csv, .hl7).

Download a File

curl "https://api.esus.health/files/{fileId}" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  --output downloaded.pdf

The response always uses Content-Disposition: attachment and X-Content-Type-Options: nosniff, so uploaded HTML/SVG/PDF can never render inside the API origin. Content-Type is the server-detected MIME type.

A fileId that does not exist, was deleted, or belongs to another organization returns 404 ({ "error": "File not found" }).

Delete a File

curl -X DELETE "https://api.esus.health/files/{fileId}" \
  -H "Authorization: Bearer YOUR_TOKEN"

Returns 200 with { "success": true }. The stored bytes are removed; the file’s metadata record is kept (marked as deleted) so the audit trail still resolves. FHIR resources that still point at the file are not modified — update them yourself.

Reference the File from a FHIR Resource

For a clinical note:

{
  "status": "current",
  "subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "content": [{
    "attachment": {
      "contentType": "application/pdf",
      "url": "https://api.esus.health/files/b8f0c2d1-9e3a-4f5b-8c7d-1a2b3c4d5e6f",
      "title": "Progress note"
    }
  }]
}

For an image (POST /fhir/Media):

{
  "status": "completed",
  "subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "content": {
    "contentType": "image/jpeg",
    "url": "https://api.esus.health/files/b8f0c2d1-9e3a-4f5b-8c7d-1a2b3c4d5e6f"
  }
}

Every upload, download and delete (successful or not) is recorded in the audit trail.