Explore documentation

File Storage

Uploading and managing clinical files and attachments

Set up the SDK server client to run the examples using esus. The REST examples use a session token. To run them with the SDK’s API key, send X-API-Key instead of Authorization.

The File Storage API uploads, downloads, and deletes binary files that belong to your organization. These are typically attachments for FHIR DocumentReference or Media resources. Endpoints live under /files.

Access: requires the File permission (File.create to upload, File.read to download, File.delete to delete). Every access, including failed attempts, is written to the audit log.

Every upload goes through these checks before it is stored:

  1. Content check: the file’s bytes must match an allowed format, and the filename extension and declared MIME type must agree with it. Otherwise, the API returns 415.
  2. Antivirus scan (ClamAV): infected files are rejected with 422. If a scanner is configured and unavailable, the upload is also rejected.
  3. Tenant binding: the file is recorded under the caller’s organization. Other organizations get 404 for it.

Upload a File

Send multipart/form-data with a single file field. The maximum size is 50 MB.

REST
curl -X POST https://api.esus.health/files/upload \
  -H "Authorization: Bearer TOKEN" \
  -F "file=@/path/to/lab-report.pdf"
SDK
const uploaded = await esus.files.upload(file);

Pass upload a File with a name and MIME type. Consume or cancel the stream returned by download.

Response: 200 OK

{
  "id": "9f8e7d6c-5b4a-3210-fedc-ba9876543210",
  "key": "11112222-3333-4444-5555-666677778888/a1b2c3d4e5f6a7b8.pdf",
  "contentType": "application/pdf",
  "size": 245760,
  "url": "/files/9f8e7d6c-5b4a-3210-fedc-ba9876543210"
}
  • id is the file handle. Use it for GET /files/{id} and DELETE /files/{id}.
  • key is the internal storage path (<organizationId>/<random>.<ext>).
  • url is the authenticated relative path /files/{id}. Add the API origin for attachment.url. key identifies the object in storage.
  • contentType is the server-detected MIME type. Use it as attachment.contentType.

Uploads are rate-limited to 10 per user per minute. Above that, the API returns 429 with a Retry-After header.

Allowed Formats

FormatMIME type (detected)Extensions
PDFapplication/pdf.pdf
JPEGimage/jpeg.jpg, .jpeg
PNGimage/png.png
GIFimage/gif.gif
WebPimage/webp.webp
DICOMapplication/dicom.dcm, .dicom
ZIP / Office Open XMLapplication/zip.zip, .docx, .xlsx, .pptx
Legacy Officeapplication/vnd.ms-office.doc, .xls, .ppt
Plain text (ASCII)text/plain.txt, .csv, .hl7

Anything else, such as video, or JSON saved with a .json extension, is rejected with 415:

{ "error": "Unsupported or mismatched file type", "detail": "file contents do not match any allowed format" }

Download a File

REST
curl "https://api.esus.health/files/9f8e7d6c-5b4a-3210-fedc-ba9876543210" \
  -H "Authorization: Bearer TOKEN" \
  -o downloaded-report.pdf
SDK
const { body, headers } = await esus.files.download(fileId);

The response body is the file. It is sent with the recorded Content-Type, Content-Disposition: attachment, and X-Content-Type-Options: nosniff, so uploaded HTML, SVG, or PDF content is never rendered inline in the API’s origin. Unknown, deleted, or other-organization ids return 404 ({ "error": "File not found" }).

Delete a File

REST
curl -X DELETE "https://api.esus.health/files/9f8e7d6c-5b4a-3210-fedc-ba9876543210" \
  -H "Authorization: Bearer TOKEN"
SDK
await esus.files.delete(fileId);

Response: 200 OK

{ "success": true }

The stored object is removed and cannot be recovered. The metadata record is kept, marked as deleted, so the audit trail still resolves.

Linking Files to FHIR Resources

Reference the file from the attachment by its /files/{id} URL. The patient goes as a flat id (subjectId), not as a nested reference.

DocumentReference (lab report)

REST
curl -X POST https://api.esus.health/fhir/DocumentReference \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/fhir+json" \
  -d '{
    "status": "current",
    "type": {
      "coding": [{
        "system": "http://loinc.org",
        "code": "11502-2",
        "display": "Laboratory report"
      }]
    },
    "subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "date": "2026-04-21",
    "content": [{
      "attachment": {
        "contentType": "application/pdf",
        "url": "https://api.esus.health/files/9f8e7d6c-5b4a-3210-fedc-ba9876543210",
        "title": "Lab report Apr 21",
        "size": 245760
      }
    }]
  }'
SDK
const created = await esus.fhir.create("DocumentReference", {
  "status": "current",
  "type": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "11502-2",
        "display": "Laboratory report"
      }
    ]
  },
  "subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "date": "2026-04-21",
  "content": [
    {
      "attachment": {
        "contentType": "application/pdf",
        "url": "https://api.esus.health/files/9f8e7d6c-5b4a-3210-fedc-ba9876543210",
        "title": "Lab report Apr 21",
        "size": 245760
      }
    }
  ]
});

Media (clinical image)

REST
curl -X POST https://api.esus.health/fhir/Media \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/fhir+json" \
  -d '{
    "status": "completed",
    "type": {
      "coding": [{
        "system": "http://terminology.hl7.org/CodeSystem/media-type",
        "code": "image"
      }]
    },
    "subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "createdDateTime": "2026-04-21",
    "content": {
      "contentType": "image/jpeg",
      "url": "https://api.esus.health/files/1a2b3c4d-5e6f-7081-9209-3a4b5c6d7e8f"
    }
  }'
SDK
const created = await esus.fhir.create("Media", {
  "status": "completed",
  "type": {
    "coding": [
      {
        "system": "http://terminology.hl7.org/CodeSystem/media-type",
        "code": "image"
      }
    ]
  },
  "subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "createdDateTime": "2026-04-21",
  "content": {
    "contentType": "image/jpeg",
    "url": "https://api.esus.health/files/1a2b3c4d-5e6f-7081-9209-3a4b5c6d7e8f"
  }
});

Limits and Best Practices

LimitValue
Maximum file size50 MB
Uploads10 per user per minute
FormatsSee Allowed Formats
  • Link uploads to a FHIR resource right away. A file with no resource pointing at it has no clinical context.
  • Deleting a FHIR resource does not delete its files. Call DELETE /files/{id} yourself if you need to.
  • For imaging larger than 50 MB, use a DICOM/PACS system and reference its URL in Media.content.url.