This guide demonstrates how to integrate S3-compatible storage with Aidbox using local min.io and a front-end application exclusively.
The application enables saving and retrieving a patient’s photo in an AWS S3 bucket via Aidbox, which acts as a middleware between the front-end and AWS S3. Aidbox manages the Access Key ID and Secret Access Key for an IAM user or role through an AwsAccount resource.
git clone git@github.com:Aidbox/examples.git
docker compose up
minioadmin
and password minioadmin
.Access Key
and Secret Key
.id: my-account
access-key-id:
9. **Set up a [Basic Client](https://docs.aidbox.app/modules/security-and-access-control/auth/basic-auth)** to allow front-end requests:
```http
PUT /Client/basic?_pretty=true
content-type: application/json
accept: application/json
{
"secret": "secret",
"grant_types": [
"basic"
]
}
{ “engine”: “allow”, “link”: [ { “id”: “basic”, “resourceType”: “Client” } ] }
Now we can use Basic Authorization header in the front-end:
“Authorization”: “Basic YmFzaWM6c2VjcmV0”
We use it in `src/constants.ts` file.
## Running the application
1. Install dependencies:
```bash
npm install
npm run dev
http://localhost:3000
.To save Patient and DocumentReference resources and the photo in the bucket:
filename: patient.png
2. Receive a [pre-signed URL](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html) from Aidbox.
AWS:
```json
{
"url": "https://<your-bucket-name>.s3.amazonaws.com/patient.png?..."
}
MinIO:
{
"url": "http://127.0.0.1:9000/mybucket/John_Smith_20250226.png?..."
}
GET /aws/storage/<your-account-id-in-aidbox>/<your-bucket-name>/<filename>
AWS:
{
"url": "https://<your-bucket-name>.s3.amazonaws.com/patient.png?..."
}
MinIO:
{
"url": "http://127.0.0.1:9000/mybucket/John_Smith_20250226.png?..."
}
<img
src="<signed-url>"
/>
In this example, the Attachment FHIR datatype is used to store the file’s URL. Specifically, the Patient.photo field contains an attachment representing the saved photo.
{
"name": [
{
"given": [
"John"
],
"family": "Smith"
}
],
"photo": [
{
"url": "http://127.0.0.1:9000/mybucket/John_Smith_20250226.png",
"title": "John_Smith_20250226.png",
"contentType": "image/png"
}
],
"birthDate": "2025-02-26",
"resourceType": "Patient",
"id": "8f886cb7-fab3-448b-977c-0b7226b9fe9f",
"meta": {
"lastUpdated": "2025-02-26T13:50:59.295229Z",
"versionId": "38",
"extension": [
{
"url": "ex:createdAt",
"valueInstant": "2025-02-26T13:50:59.295229Z"
}
]
}
}
Additionally, a DocumentReference resource can be created to store metadata about the image. See DocumentReference’s scope and usagee.
{
"status": "current",
"content": [
{
"attachment": {
"url": "http://127.0.0.1:9000/mybucket/John_Smith_20250226.png",
"title": "John_Smith_20250226.png",
"contentType": "image/png"
}
}
],
"resourceType": "DocumentReference",
"id": "5e390018-2f27-49a4-839a-4b0e10391bf1",
"meta": {
"lastUpdated": "2025-02-26T13:50:59.277060Z",
"versionId": "37",
"extension": [
{
"url": "ex:createdAt",
"valueInstant": "2025-02-26T13:50:59.277060Z"
}
]
}
}