The Filestack client, the entry point for all public methods. Encapsulates session information.

### Example

    // ES module
    import * as filestack from 'filestack-js';
    const client = filestack.init('apikey');

    // UMD module in browser
    <script src="https://static.filestackapi.com/filestack-js/1.x.x/filestack.min.js"></script>
    const client = filestack.init('apikey');

### Type parameters

- #### EventTypes: string | symbol | object

### Hierarchy

- EventEmitter
  - Client

## Index

### Interfaces

- EventEmitterStatic
- ListenerFn

### Constructors

- constructor

### Properties

- session
- EventEmitter
- prefixed

### Methods

- addListener
- emit
- eventNames
- listenerCount
- listeners
- logout
- metadata
- multiupload
- off
- on
- once
- picker
- preview
- remove
- removeAllListeners
- removeListener
- removeMetadata
- retrieve
- setCname
- setSecurity
- storeURL
- transform
- upload

## Constructors

### constructor

- new Client(apikey: string, options?: ClientOptions): Client

- - Defined in lib/client.ts:94

  #### Parameters

  - ##### apikey: string

  - ##### Optional options: ClientOptions

  #### Returns Client

## Properties

### session

session: Session

- Defined in lib/client.ts:93

### Static EventEmitter

EventEmitter: EventEmitterStatic

- Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:64

### Static prefixed

prefixed: string | boolean

Inherited from EventEmitter.prefixed

- Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:9

## Methods

### addListener

- addListener<T>(event: T, fn: ListenerFn<EventArgs<EventTypes, T>>, context?: any): this

- Inherited from EventEmitter.addListener

  - Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:36

  #### Type parameters

  - #### T: EventNames<EventTypes>

  #### Parameters

  - ##### event: T

  - ##### fn: ListenerFn<EventArgs<EventTypes, T>>

  - ##### Optional context: any

  #### Returns this

### emit

- emit<T>(event: T, ...args: EventArgs<EventTypes, T>): boolean

- Inherited from EventEmitter.emit

  - Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:30

  Calls each of the listeners registered for a given event.

  #### Type parameters

  - #### T: EventNames<EventTypes>

  #### Parameters

  - ##### event: T

  - ##### Rest ...args: EventArgs<EventTypes, T>

  #### Returns boolean

### eventNames

- eventNames(): Array<EventNames<EventTypes>>

- Inherited from EventEmitter.eventNames

  - Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:15

  Return an array listing the events for which the emitter has registered listeners.

  #### Returns Array<EventNames<EventTypes>>

### listenerCount

- listenerCount(event: EventNames<EventTypes>): number

- Inherited from EventEmitter.listenerCount

  - Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:25

  Return the number of listeners listening to a given event.

  #### Parameters

  - ##### event: EventNames<EventTypes>

  #### Returns number

### listeners

- listeners<T>(event: T): Array<ListenerFn<EventArgs<EventTypes, T>>>

- Inherited from EventEmitter.listeners

  - Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:20

  Return the listeners registered for a given event.

  #### Type parameters

  - #### T: EventNames<EventTypes>

  #### Parameters

  - ##### event: T

  #### Returns Array<ListenerFn<EventArgs<EventTypes, T>>>

### logout

- logout(name?: string): Promise<any>

- - Defined in lib/client.ts:161

  Clear all current cloud sessions in the picker. Optionally pass a cloud source name to only log out of that cloud source. This essentially clears the OAuth authorization codes from the Filestack session.

  #### Parameters

  - ##### Optional name: string

    Optional cloud source name.

  #### Returns Promise<any>

### metadata

- metadata(handle: string, options?: MetadataOptions, security?: Security): Promise<any>

- - Defined in lib/client.ts:184

  Retrieve detailed data of stored files.

  ### Example

      client
        .metadata('DCL5K46FS3OIxb5iuKby')
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        }));

  see

    File API - Metadata.

  #### Parameters

  - ##### handle: string

    Valid Filestack handle.

  - ##### Optional options: MetadataOptions

    Metadata fields to enable on response.

  - ##### Optional security: Security

    Optional security override.

  #### Returns Promise<any>

### multiupload

- multiupload(file: InputFile[], options?: UploadOptions, storeOptions?: StoreUploadOptions, token?: any, security?: Security): Promise<any>

- - Defined in lib/client.ts:442

  Initiates a multi-part upload flow. Use this for Filestack CIN and FII uploads.

  In Node runtimes the file argument is treated as a file path. Uploading from a Node buffer is not yet implemented.

  ### Example

      const token = {};
      const onRetry = (obj) => {
        console.log(`Retrying ${obj.location} for ${obj.filename}. Attempt ${obj.attempt} of 10.`);
      };

      client.multiupload([file], { onRetry }, token)
        .then(res => console.log(res));

      client.multiupload([{file, name}], { onRetry }, token)
        .then(res => console.log(res));

      token.pause();  // Pause flow
      token.resume(); // Resume flow
      token.cancel(); // Cancel flow (rejects)

  #### Parameters

  - ##### file: InputFile[]

    Must be a valid [File | Blob | Buffer | string (base64)]

  - ##### Optional options: UploadOptions

  - ##### Optional storeOptions: StoreUploadOptions

    Storage options.

  - ##### Optional token: any

    A control token that can be used to call cancel(), pause(), and resume().

  - ##### Optional security: Security

    Optional security policy and signature override.

  #### Returns Promise<any>

### off

- off<T>(event: T, fn?: ListenerFn<EventArgs<EventTypes, T>>, context?: any, once?: boolean): this

- Inherited from EventEmitter.off

  - Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:47

  #### Type parameters

  - #### T: EventNames<EventTypes>

  #### Parameters

  - ##### event: T

  - ##### Optional fn: ListenerFn<EventArgs<EventTypes, T>>

  - ##### Optional context: any

  - ##### Optional once: boolean

  #### Returns this

### on

- on<T>(event: T, fn: ListenerFn<EventArgs<EventTypes, T>>, context?: any): this

- Inherited from EventEmitter.on

  - Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:35

  Add a listener for a given event.

  #### Type parameters

  - #### T: EventNames<EventTypes>

  #### Parameters

  - ##### event: T

  - ##### fn: ListenerFn<EventArgs<EventTypes, T>>

  - ##### Optional context: any

  #### Returns this

### once

- once<T>(event: T, fn: ListenerFn<EventArgs<EventTypes, T>>, context?: any): this

- Inherited from EventEmitter.once

  - Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:41

  Add a one-time listener for a given event.

  #### Type parameters

  - #### T: EventNames<EventTypes>

  #### Parameters

  - ##### event: T

  - ##### fn: ListenerFn<EventArgs<EventTypes, T>>

  - ##### Optional context: any

  #### Returns this

### picker

- picker(options?: PickerOptions): PickerInstance

- - Defined in lib/client.ts:191

  Construct a new picker instance.

  #### Parameters

  - ##### Optional options: PickerOptions

  #### Returns PickerInstance

### preview

- preview(handle: string, options?: PreviewOptions): HTMLIFrameElement | Window

- - Defined in lib/client.ts:209

  Used for viewing files via Filestack handles or storage aliases, requires Document Viewer addon to your Filestack application. Opens document viewer in new window if id option is not provided.

  ### Example

      // <div id="preview"></div>

      client.preview('DCL5K46FS3OIxb5iuKby', { id: 'preview' });

  #### Parameters

  - ##### handle: string

    Valid Filestack handle.

  - ##### Optional options: PreviewOptions

    Preview options

  #### Returns HTMLIFrameElement | Window

### remove

- remove(handle: string, security?: Security): Promise<any>

- - Defined in lib/client.ts:234

  Remove a file from storage and the Filestack system.

  Requires a valid security policy and signature. The policy and signature will be pulled from the client session, or it can be overridden with the security parameter.

  ### Example

      client
        .remove('DCL5K46FS3OIxb5iuKby')
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        }));

  see

    File API - Delete

  #### Parameters

  - ##### handle: string

    Valid Filestack handle.

  - ##### Optional security: Security

    Optional security override.

  #### Returns Promise<any>

### removeAllListeners

- removeAllListeners(event?: EventNames<EventTypes>): this

- Inherited from EventEmitter.removeAllListeners

  - Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:52

  Remove all listeners, or those of the specified event.

  #### Parameters

  - ##### Optional event: EventNames<EventTypes>

  #### Returns this

### removeListener

- removeListener<T>(event: T, fn?: ListenerFn<EventArgs<EventTypes, T>>, context?: any, once?: boolean): this

- Inherited from EventEmitter.removeListener

  - Defined in /Users/pcholuj/Documents/projects/filestack-js/node_modules/eventemitter3/index.d.ts:46

  Remove the listeners of a given event.

  #### Type parameters

  - #### T: EventNames<EventTypes>

  #### Parameters

  - ##### event: T

  - ##### Optional fn: ListenerFn<EventArgs<EventTypes, T>>

  - ##### Optional context: any

  - ##### Optional once: boolean

  #### Returns this

### removeMetadata

- removeMetadata(handle: string, security?: Security): Promise<any>

- - Defined in lib/client.ts:259

  Remove a file only from the Filestack system. The file remains in storage.

  Requires a valid security policy and signature. The policy and signature will be pulled from the client session, or it can be overridden with the security parameter.

  ### Example

      client
        .removeMetadata('DCL5K46FS3OIxb5iuKby')
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        }));

  see

    File API - Delete

  #### Parameters

  - ##### handle: string

    Valid Filestack handle.

  - ##### Optional security: Security

    Optional security override.

  #### Returns Promise<any>

### retrieve

- retrieve(handle: string, options?: RetrieveOptions, security?: Security): Promise<Object | Blob>

- - Defined in lib/client.ts:310

  Access files via their Filestack handles.

  If head option is provided - request headers are returned in promise If metadata option is provided - metadata object is returned in promise Otherwise file blob is returned Metadata and head options cannot be mixed

  ### Example

      client.retrieve('fileHandle', {
       metadata: true,
      }).then((response) => {
       console.log(response);
      }).catch((err) => {
       console.error(err);
      })

  see

    File API - Download

  throws

    Error

  #### Parameters

  - ##### handle: string

    Valid file handle

  - ##### Optional options: RetrieveOptions

    RetrieveOptions

  - ##### Optional security: Security

    Optional security override.

  #### Returns Promise<Object | Blob>

### setCname

- setCname(cname: string): void

- - Defined in lib/client.ts:146

  Set custom cname

  memberof

    Client

  #### Parameters

  - ##### cname: string

  #### Returns void

### setSecurity

- setSecurity(security: Security): void

- - Defined in lib/client.ts:128

  Set security object

  memberof

    Client

  #### Parameters

  - ##### security: Security

  #### Returns void

### storeURL

- storeURL(url: string, options?: StoreParams, token?: any, security?: Security): Promise<Object>

- - Defined in lib/client.ts:279

  Store a file from its URL.

  ### Example

      client
        .storeURL('https://d1wtqaffaaj63z.cloudfront.net/images/NY_199_E_of_Hammertown_2014.jpg')
        .then(res => console.log(res));

  see

    File API - Store

  #### Parameters

  - ##### url: string

    Valid URL to a file.

  - ##### Optional options: StoreParams

    Configure file storage.

  - ##### Optional token: any

    Optional control token to call .cancel()

  - ##### Optional security: Security

    Optional security override.

  #### Returns Promise<Object>

### transform

- transform(url: string | string[], options: TransformOptions, b64?: boolean): string

- - Defined in lib/client.ts:348

  Interface to the Filestack Processing API. Convert a URL, handle, or storage alias to another URL which links to the transformed file. You can optionally store the returned URL with client.storeURL.

  Transform params can be provided in camelCase or snakeCase style ie: partial_pixelate or partialPixelate

  ### Example

      const transformedUrl = client.transform(url, {
        crop: {
          dim: [x, y, width, height],
        },
        vignette: {
          blurmode: 'gaussian',
          amount: 50,
        },
        flip: true,
        partial_pixelate: {
          objects: [[10, 20, 200, 250], [275, 91, 500, 557]],
        },
      };

      // optionally store the new URL
      client.storeURL(transformedUrl).then(res => console.log(res));

  see

    Filestack Processing API

  #### Parameters

  - ##### url: string | string[]

    Single or multiple valid URLs (http(s)://), file handles, or storage aliases (src://) to an image.

  - ##### options: TransformOptions

    Transformations are applied in the order specified by this object.

  - ##### Default value b64: boolean = false

    Use new more safe format for generating transforms url (default=false) Note: If there will be any issues with url please test it with enabled b64 support

  #### Returns string

  A new URL that points to the transformed resource.

### upload

- upload(file: InputFile, options?: UploadOptions, storeOptions?: StoreUploadOptions, token?: any, security?: Security): Promise<any>

- - Defined in lib/client.ts:385

  Initiates a multi-part upload flow. Use this for Filestack CIN and FII uploads.

  In Node runtimes the file argument is treated as a file path. Uploading from a Node buffer is not yet implemented.

  ### Example

      const token = {};
      const onRetry = (obj) => {
        console.log(`Retrying ${obj.location} for ${obj.filename}. Attempt ${obj.attempt} of 10.`);
      };

      client.upload(file, { onRetry }, { filename: 'foobar.jpg' }, token)
        .then(res => console.log(res));

      client.upload({file, name}, { onRetry }, { filename: 'foobar.jpg' }, token)
        .then(res => console.log(res));

      token.pause();  // Pause flow
      token.resume(); // Resume flow
      token.cancel(); // Cancel flow (rejects)

  #### Parameters

  - ##### file: InputFile

    Must be a valid [File | Blob | Buffer | string]

  - ##### Optional options: UploadOptions

  - ##### Optional storeOptions: StoreUploadOptions

    Storage options.

  - ##### Optional token: any

    A control token that can be used to call cancel(), pause(), and resume().

  - ##### Optional security: Security

    Optional security policy and signature override.

  #### Returns Promise<any>