Options
All
  • Public
  • Public/Protected
  • All
Menu

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');

Hierarchy

  • Client

Index

Constructors

constructor

Properties

session

session: Session

Methods

logout

  • logout(name?: string): Promise<Object>
  • 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<Object>

metadata

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

picker

preview

  • preview(handle: string, options?: PreviewOptions): HTMLIFrameElement | Window
  • 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>
  • 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>

removeMetadata

  • removeMetadata(handle: string, security?: Security): 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>

retrieve

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

storeURL

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

      Configure file storage.

    • Optional token: any

      Optional control token to call .cancel()

    • Optional security: Security

      Optional security override.

    Returns Promise<Object>

transform

  • 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

      Valid URL (http(s)://), file handle, or storage alias (src://) to an image.

    • options: TransformOptions

      Transformations are applied in the order specified by this object.

    Returns string

    A new URL that points to the transformed resource.

upload

  • 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));
    
    token.pause();  // Pause flow
    token.resume(); // Resume flow
    token.cancel(); // Cancel flow (rejects)
    

    Parameters

    • file: any

      Must be a valid File, Blob, base64 encoded string, or file path in Node.

    • Optional options: UploadOptions
    • Optional storeOptions: StoreOptions

      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>