Class Client

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/3.x.x/filestack.min.js"></script>
const client = filestack.init('apikey');

Hierarchy

  • EventEmitter
    • Client

Constructors

Properties

session: Session

Accessors

  • get utils(): __module
  • Returns filestack utils

    Memberof

    Client

    Returns __module

Methods

  • Download file by handle

    Browser Example

    client.download('fileHandle').then((response) => {
    const img = new Image();
    img.src = URL.createObjectURL(res.data)
    document.body.appendChild(img);
    }).catch((err) => {
    console.error(err);
    })

    See

    File API - Download

    Throws

    Error

    Parameters

    • handle: string

      Valid file handle

    • Optional security: Security

    Returns Promise<FsResponse>

  • 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>

  • 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>

  • 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)

    Returns

    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>

  • 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 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>

  • 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>

  • 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

    Deprecated

    use metadata or download methods instead

    Throws

    Error

    Parameters

    • handle: string

      Valid file handle

    • Optional options: RetrieveOptions

      RetrieveOptions

    • Optional security: Security

      Optional security override.

    Returns Promise<Object | Blob>

  • Set custom cname

    Returns

    Memberof

    Client

    Parameters

    • cname: string

    Returns void

  • 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 storeParams: StoreParams
    • Optional token: any

      Optional control token to call .cancel()

    • Optional security: Security

      Optional security override.

    • Optional uploadTags: UploadTags

      Optional tags visible in webhooks.

    • Optional headers: {
          [key: string]: string;
      }

      Optional headers to send

      • [key: string]: string
    • Optional workflowIds: string[]

      Optional workflowIds to send

    Returns Promise<Object>

  • 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

    Returns

    A new URL that points to the transformed resource.

    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.

    • 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

  • 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)

    Returns

    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>