JavaScript SDK
What’s in the box?
- A multi-part uploader powered on the backend by the Filestack CIN.
- An interface to the Filestack Processing Engine for transforming assets via URLs.
- The Filestack Picker – an upload widget for the web that integrates over a dozen cloud providers and provides pre-upload image editing.
Installation
npm install filestack-jsTo get your free API key, sign up for a Filestack account here: https://dev.filestack.com/signup/free.
API Documentation
Usage
ES module
import * as filestack from 'filestack-js';
const client = filestack.init('apikey');
UMD module
<script src="//static.filestackapi.com/filestack-js/{MAJOR_VERSION}.x.x/filestack.min.js" crossorigin="anonymous"></script>
<script>
const client = filestack.init('apikey');
</script>
<script src="//static.filestackapi.com/filestack-js/4.x.x/filestack.min.js" crossorigin="anonymous"></script>
<script>
const client = filestack.init('apikey');
</script>
SRI
<script src="//static.filestackapi.com/filestack-js/{LIBRARY_VERSION}/filestack.min.js.gz" integrity="{FILE_HASH}" crossorigin="anonymous"></script>
Where {LIBRARY_VERSION} is currently used library version and {FILE_HASH} is one of the hashes from integrity field in manifest.json file.
CommonJS module
const client = require('filestack-js').init('apikey');
Module Overview
The package.json specifies two separate modules: main for the CommonJS module (intended for Node runtimes) browser for the pre-bundled ES module (intended for browser runtimes).
Live examples (JSFiddle)
npm run examplesPicker Quick Start
If you are here to use the picker widget, it can be initialized from the Filestack client by calling client.picker(options). Options for the picker are documented here.
- open – Create the application and mount it into the DOM based on the displayMode.
- close – Close the application and remove its resources from the DOM.
- crop(files) – Create the application, mount it, and pre-select the passed files for cropping.
- cancel – Cancel all uploads controlled by this instance.
Polyfills
- Module (for bundling):
- https://babeljs.io/docs/en/babel-polyfill
Development
npm testDebugging
Filestack-js uses debug, so just run with environmental variable DEBUG set to fs.*.
Node
DEBUG=fs.* node example_upload.jsBrowser
localStorage.debug = 'fs:*'Error event
The upload.error event was added to the SDK. To obtain every upload request error just add callback to it. Error contains details field with responseBody, responseHeaders, code (only when error type is FilestackErrorType.REQUEST)
<script>
const client = filestack.init('apikey');
client.on('upload.error', (filestackError) => {
console.log(filestackError);
});
</script>
Sentry Integration
If you’re using Sentry to monitor your application, Filestack will automatically report upload errors to Sentry, and tag them with helpful diagnostic information via @sentry/browser.