Repository navigation
RFC: Presigned Binary Upload URLs ($generate-upload-url)
#7902
codyebberson
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
1. Background & Motivation
Medplum’s FHIR server provides robust
Binarysupport for documents, images, videos, and large artifacts. Today, clients typically create Binaries via:Some customers now require the ability to upload large volumes of files directly to object storage without routing bytes through the Medplum API tier, especially for:
To support this, Medplum will introduce a special-case, advanced FHIR Operation for generating presigned upload URLs.
The primary and recommended path for most users remains:
POST /Binary.$generate-upload-urlis reserved for situations where direct-to-storage uploads are required.2. Operation Overview:
$generate-upload-urlA new type-level FHIR Operation:
This operation:
Accepts a Binary template (metadata only, no content) inside a
ParametersresourceCreates a new Binary resource in Medplum
Generates a storage-backed presigned upload URL
Returns:
This design keeps the Binary lifecycle fully FHIR-native while supporting large uploads outside the Medplum API tier.
3. Request Format
Request is a FHIR
Parametersresource:Parameters
binarycontentLengthmaxExpiresInfilenamebinarymust not contain adatafield.Example Request
{ "resourceType": "Parameters", "parameter": [ { "name": "binary", "resource": { "resourceType": "Binary", "contentType": "image/jpeg", "securityContext": { "reference": "Patient/123" } } }, { "name": "contentLength", "valueInteger": 5242880 }, { "name": "filename", "valueString": "chest-xray.jpg" }, { "name": "maxExpiresIn", "valueInteger": 900 } ] }Minimal request:
{ "resourceType": "Parameters", "parameter": [ { "name": "binary", "resource": { "resourceType": "Binary", "contentType": "image/jpeg" } } ] }4. Server Behavior
Validate Binary template
contentTypedatafieldsecurityContextCreate Binary resource
idupload-pendingtagCompute upload constraints
maxSizefrom:contentLength, orTTL from:
maxExpiresIn, orGenerate presigned upload URL
Return FHIR
Parameterscontaining:uploadDetailswith URL, headers, max size, expirationExample Response
{ "resourceType": "Parameters", "parameter": [ { "name": "binary", "resource": { "resourceType": "Binary", "id": "abc123", "contentType": "image/jpeg", "securityContext": { "reference": "Patient/123" }, "meta": { "tag": [ { "system": "http://medplum.com/tags/binary-status", "code": "upload-pending" } ] } } }, { "name": "uploadDetails", "part": [ { "name": "url", "valueUri": "https://s3.example.com/.../abc123" }, { "name": "httpMethod", "valueCode": "PUT" }, { "name": "headers", "part": [ { "name": "Content-Type", "valueString": "image/jpeg" } ] }, { "name": "maxSize", "valueInteger": 5242880 }, { "name": "expiresAt", "valueInstant": "2025-11-24T09:00:00Z" } ] } ] }5. Upload Completion
No dedicated
$mark-upload-completeis included in v1.Completion is handled internally by Medplum:
Storage triggers (S3 Events, GCS Pub/Sub, Azure EventGrid)
Background workers that:
upload-pendingClients may optionally poll
GET /Binary/{id}.6. Bulk / Batch Considerations (Important)
Some customers need to generate hundreds or thousands of upload URLs during large data imports.
There are two potential approaches:
❌ Option A: Extend
$generate-upload-urlwithcountWe will not add a
countparameter.Reasoning:
contentType,securityContext,meta, etc.countparameter cannot express per-file differences.countBinaries would require new, more complex structures (arrays of Binary templates, arrays of results).Conclusion:
$generate-upload-urlstays single input → single output.✅ Option B (Recommended): Use standard FHIR
BundlebatchingClients should submit a FHIR
Bundleof typebatchcontaining many$generate-upload-urlentries.Example:
{ "resourceType": "Bundle", "type": "batch", "entry": [ { "request": { "method": "POST", "url": "Binary/$generate-upload-url" }, "resource": { "resourceType": "Parameters", "parameter": [ { "name": "binary", "resource": { "resourceType": "Binary", "contentType": "image/jpeg", "securityContext": { "reference": "Patient/123" } }} ] } }, { "request": { "method": "POST", "url": "Binary/$generate-upload-url" }, "resource": { "resourceType": "Parameters", "parameter": [ { "name": "binary", "resource": { "resourceType": "Binary", "contentType": "application/pdf", "securityContext": { "reference": "Patient/456" } }} ] } } // ...more entries... ] }Advantages
Server recommendation
Result
This keeps
$generate-upload-urlclean and predictable, and gives customers a scalable batching mechanism.7. Security & Multi-Tenancy
$generate-upload-urlcalls are rate-limitedAuditEvent8. Future Extensions
strategy: multipart)$generate-download-urlsibling operation9. OperationDefinition Summary (Conceptual)
$generate-upload-urlBinaryParametersParametersAll reactions