Open file picker

Open the platform's file picker

Opens the platform's file picker, uploads the selected file(s), and resolves with an array of the uploaded files' metadata. The upload runs in the parent window, so custom components can upload without direct access to the authenticated upload endpoints.

Parameter

ParameterTypeDescription
optionsObjectFile picker configuration. See the properties listed below.

The options object accepts the following properties:

PropertyTypeDescription
fileExtensionsString[]Allowed file extensions, e.g. ["JPG", "PNG"].
maxSizeNumberMaximum allowed file size, in bytes.
maxCountNumberMaximum number of files that can be selected.
imagePropsObjectImage constraints — sizes ([width, height] pairs) and crop flag.

Syntax

kf.client.openFilePicker(options).then((files) => {...})

or

const files = await kf.client.openFilePicker(options);

Returns

Returns a promise that always resolves with an array of the uploaded files' metadata objects (each including key, name, size, photos, etc.). Resolves with [] if the picker is closed without completing any upload.

Example

To upload a single image and pass it to the field's change handler.

const files = await kf.client.openFilePicker({ fileExtensions: ["JPG", "PNG"], maxCount: 1 });
if (files.length) onChange(files[0]);

To upload multiple attachments.

const files = await kf.client.openFilePicker({ maxCount: 10 });
if (files.length) onChange([...existing, ...files]);

On this page