core.medplumclient.createattachment | Medplum
MedplumClient.createAttachment() method
Creates a FHIR Attachment with the provided data content.
This is a convenience method for creating a Binary resource and then creating an Attachment element.
The data parameter can be a string or a File object.
A File object often comes from a <input type="file"> element.
Signature:
createAttachment(createBinaryOptions: CreateBinaryOptions, requestOptions?: MedplumRequestOptions): Promise<Attachment>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| createBinaryOptions | CreateBinaryOptions | The binary options. See CreateBinaryOptions for full details. |
| requestOptions | MedplumRequestOptions | (Optional) Optional fetch options. NOTE: only options.signal is respected when onProgress is also provided. |
Returns:
Promise
The result of the create operation.
Example
Example:
const result = await medplum.createAttachment(myFile, 'test.jpg', 'image/jpeg');
console.log(result);
See the FHIR "create" operation for full details.