core.medplumclient.createattachment
Home > @medplum/core > MedplumClient > createAttachment
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(data: BinarySource, filename: string | undefined, contentType: string, onProgress?: (e: ProgressEvent) => void, options?: MedplumRequestOptions): Promise<Attachment>;
Parameters
Parameter | Type | Description |
---|---|---|
data | BinarySource | The binary data to upload. |
filename | string | undefined | Optional filename for the binary. |
contentType | string | Content type for the binary. |
onProgress | (e: ProgressEvent) => void | (Optional) Optional callback for progress events. **NOTE:** only options.signal is respected when onProgress is also provided. |
options | MedplumRequestOptions | (Optional) Optional fetch options. **NOTE:** only options.signal is respected when onProgress is also provided. |
Returns:
Promise<Attachment>
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: https://www.hl7.org/fhir/http.html\#create