Skip to main content

core.medplumclient.createbinary

Home > @medplum/core > MedplumClient > createBinary

MedplumClient.createBinary() method

Creates a FHIR Binary resource with the provided data content.

The return value is the newly created resource, including the ID and meta.

The data parameter can be a string or a File object.

A File object often comes from a <input type="file"> element.

Signature:

createBinary(data: BinarySource, filename: string | undefined, contentType: string, onProgress?: (e: ProgressEvent) => void, options?: MedplumRequestOptions): Promise<Binary>;

Parameters

ParameterTypeDescription
dataBinarySourceThe binary data to upload.
filenamestring | undefinedOptional filename for the binary.
contentTypestringContent 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.
optionsMedplumRequestOptions(Optional) Optional fetch options. **NOTE:** only options.signal is respected when onProgress is also provided.

Returns:

Promise<Binary>

The result of the create operation.

Example

Example:

const result = await medplum.createBinary(myFile, 'test.jpg', 'image/jpeg');
console.log(result.id);

See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html\#create