Skip to content

Commit dae7540

Browse files
docs(picker): acceptFn description and example (#452)
1 parent df7cee8 commit dae7540

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/lib/picker.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,20 @@ export interface PickerOptions {
371371
* - text/* <- accept all types of text files
372372
*/
373373
accept?: string | string[];
374+
/**
375+
* Custom accept check function
376+
* ```javascript
377+
* acceptFn: (file, options) => {
378+
* return options.mimeFromMagicBytes(file.originalFile).then((res) => { // we can check mimetype from magic bytes
379+
* //console.log(options.mimeFromExtension(file.originalFile.name)); // or check extension from filestack extensions database
380+
* // throw new Error('Cannot accept that file') // we can throw exception to block file upload
381+
* // return Promise.reject('Cannot accept that file'') // or reject a promise
382+
* return Promise.resolve();
383+
* });
384+
* }
385+
* ```
386+
*/
387+
acceptFn?: (PickerFileMetadata, PickerAcceptFnOptions) => Promise<string>;
374388
/**
375389
* Prevent modal close on upload failure and allow users to retry.
376390
*/
@@ -708,6 +722,27 @@ export interface PickerTransformationOptions {
708722
force?: boolean;
709723
}
710724

725+
export interface PickerAcceptFnOptions {
726+
/**
727+
* Provided accept string
728+
*/
729+
accept: string[];
730+
/**
731+
* Accept string converted to mimetype
732+
*/
733+
acceptMime: string[];
734+
/**
735+
* Mimetype based magic bytes
736+
* {@link https://filestack.github.io/filestack-js/globals.html#getmimetype}
737+
*/
738+
mimeFromMagicBytes: Promise<string>;
739+
/**
740+
* Mimetype based on file extension
741+
* {@link https://filestack.github.io/filestack-js/globals.html#extensiontomime}
742+
*/
743+
mimeFromExtension: string;
744+
}
745+
711746
/**
712747
* @private
713748
* A synchronous-looking wrapper for loading the picker and calling its methods.

0 commit comments

Comments
 (0)