Platform
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:
- 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. - Antivirus scan (ClamAV): infected files are rejected with
422. If a scanner is configured and unavailable, the upload is also rejected. - Tenant binding: the file is recorded under the caller’s organization. Other organizations get
404for it.
Upload a File
Send multipart/form-data with a single file field. The maximum size is 50 MB.
curl -X POST https://api.esus.health/files/upload \
-H "Authorization: Bearer TOKEN" \
-F "file=@/path/to/lab-report.pdf"
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"
}
idis the file handle. Use it forGET /files/{id}andDELETE /files/{id}.keyis the internal storage path (<organizationId>/<random>.<ext>).urlis the authenticated relative path/files/{id}. Add the API origin forattachment.url.keyidentifies the object in storage.contentTypeis the server-detected MIME type. Use it asattachment.contentType.
Uploads are rate-limited to 10 per user per minute. Above that, the API returns 429 with a Retry-After header.
Allowed Formats
| Format | MIME type (detected) | Extensions |
|---|---|---|
application/pdf | .pdf | |
| JPEG | image/jpeg | .jpg, .jpeg |
| PNG | image/png | .png |
| GIF | image/gif | .gif |
| WebP | image/webp | .webp |
| DICOM | application/dicom | .dcm, .dicom |
| ZIP / Office Open XML | application/zip | .zip, .docx, .xlsx, .pptx |
| Legacy Office | application/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
curl "https://api.esus.health/files/9f8e7d6c-5b4a-3210-fedc-ba9876543210" \
-H "Authorization: Bearer TOKEN" \
-o downloaded-report.pdf
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
curl -X DELETE "https://api.esus.health/files/9f8e7d6c-5b4a-3210-fedc-ba9876543210" \
-H "Authorization: Bearer TOKEN"
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)
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
}
}]
}'
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)
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"
}
}'
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
| Limit | Value |
|---|---|
| Maximum file size | 50 MB |
| Uploads | 10 per user per minute |
| Formats | See 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.