Skip to content
Last updated

Uploading Attachments

This guide describes how to upload attachments to PracSuite using a presigned S3 POST.

Get a Presigned Upload URL

To upload an attachment, first request a presigned upload URL from the PracSuite API.

Make a POST request to the endpoint like below, replacing the {client_id} as required. The request body must include the file_name (including extension) you intend to upload.

curl -X POST "https://api.pracsuite.com/v1/patient/{client_id}/patient_attachment" \
    -H "Content-Type: application/json" \
    -H "x-api-key: VENDOR_API_KEY_HERE" \
    -H "a-api-key: PRACSUITE_GENERATED_API_KEY_HERE" \
    -d '{
        "file_name": "example-file.txt"
    }'

If successful, the API will return a JSON response similar to the following:

{
    "url": "https://pracsuite-region1.s3.ap-southeast-2.amazonaws.com/",
    "fields": {
        "key": "temp/1/2/3/4/00000000-0000-0000-0000-000000000000/example-file.txt",
        "Policy": "{BASE64_ENCODED_POLICY}",
        "x-amz-algorithm": "AWS4-HMAC-SHA256",
        "x-amz-credential": "{ACCESS_KEY_ID}/{YYYYMMDD}/ap-southeast-2/s3/aws4_request",
        "x-amz-date": "{YYYYMMDD}T{HHMMSS}Z",
        "x-amz-signature": "{SIGNATURE}",
        "x-amz-security-token": "{SESSION_TOKEN}"
    }
}

Notes

  • The url and all values in fields are generated by PracSuite and must be used exactly as returned.
  • if you modify the key value, it will be rejected.
  • if the uploaded file size exceeds 100MB, it will be rejected.

Upload the file to S3

The returned URL is a presigned POST. To upload the file, perform a multipart/form-data POST to the url, including all fields exactly as provided, plus the file itself.

cURL example:

curl -X POST "https://pracsuite-region1.s3.ap-southeast-2.amazonaws.com/" \
    -F "key=temp/1/123/1/00000000-0000-0000-0000-000000000000/example-file.txt" \
    -F "Policy={BASE64_ENCODED_POLICY}" \
    -F "x-amz-algorithm=AWS4-HMAC-SHA256" \
    -F "x-amz-credential={ACCESS_KEY_ID}/{YYYYMMDD}/ap-southeast-2/s3/aws4_request" \
    -F "x-amz-date={YYYYMMDD}T{HHMMSS}Z" \
    -F "x-amz-signature={SIGNATURE}" \
    -F "x-amz-security-token={SESSION_TOKEN}" \
    -F "file=@/files/example-file.txt"

JavaScript example:

async function uploadAttachment(presignResponse, file) {
    const formData = new FormData();

    // Add all presigned fields exactly as returned
    Object.entries(presignResponse.fields).forEach(([key, value]) => {
        formData.append(key, value);
    });

    // Add the file last
    formData.append("file", file);

    const response = await fetch(presignResponse.url, {
        method: "POST",
        body: formData
    });

    if (!response.ok) {
        throw new Error(`Upload failed with status ${response.status}`);
    }

    // Successful uploads return 204 No Content
    return true;
}

Successful upload response

If the upload is successful, Amazon S3 will respond with:

  • HTTP status: 204 No Content

No response body is returned.

Important

  • All form fields are required and are case-sensitive.
  • Do not rename fields or change their values.
  • Uploading a file with a different name or extension than the original file_name may cause the upload to be rejected during validation.

After the upload completes

Once the file has been successfully uploaded to Amazon S3, PracSuite will asynchronously process and validate the attachment. This includes verification of the uploaded file against the original upload request (such as file name and extension).

After the file has been processed and verified, PracSuite creates a Patient Attachment record linked to the relevant patient.

The attachment metadata can then be retrieved by calling the Patient Attachment endpoint, for example:

curl -X GET "https://api.pracsuite.com/v1/patient/{client_id}/patient_attachment" \
  -H "x-api-key: VENDOR_API_KEY_HERE" \
  -H "a-api-key: PRACSUITE_GENERATED_API_KEY_HERE"

Notes

  • Patient Attachment records are created only after the upload has completed and passed validation.
  • There may be a short delay between a successful S3 upload and the attachment appearing in the Patient Attachment API.
  • If validation fails, the attachment record will not be created.