Removing a File with the Javascript API

If you need to delete a file, you can remove it from Filestack and any underlying storage using remove. The remove function will delete the Filestack link, Filestack's record of the metadata for the file, and the file itself if it was stored to S3 or another custom storage option.

Syntax

Note: Security policies and signatures should be included as options when the client is initialized with your API key if your account has security enabled.

<script src="https://static.filestackapi.com/v3/filestack-0.5.2.js"></script>
<script type="text/javascript">
  var client = filestack.init('yourApiKey', { policy: 'policy', signature: 'signature' });
  client.remove(handle);
</script>
Important:

Filestack has added an additional layer of security that will be required in order to perform a remove call. This change is detailed here.

Remove requests will require a valid filestack policy and signature with the remove permission. Details on creating and using Filestack policies and signatures can be found in the Security section of the documentation.

Security Documentation

Example Remove Code

Create a file and then remove the file, then confirm removal
var client = filestack.init("AJxHNUUcQHG6ZC0aksrb1z", { policy: "eyJleHBpcnkiOjE2ODgxMzkwNTIsImNhbGwiOlsic3RvcmUiLCJyZW1vdmUiXX0=", signature: "d42db977580f14653f98b19d41a2c5cc3dcc7cd6db6f0de4cd85db3ee8babe3a" }) console.log("Storing https://d1wtqaffaaj63z.cloudfront.net/images/NY_199_E_of_Hammertown_2014.jpg"); var url = 'https://d1wtqaffaaj63z.cloudfront.net/images/NY_199_E_of_Hammertown_2014.jpg' client.storeURL(url).then((result) => { var storedurl = result.url console.log(storedurl) console.log('removing file') var handle = storedurl.substr(storedurl.lastIndexOf("/") + 1) console.log(handle) client.remove(handle) console.log('file removed successfully: ' + storedurl) })

Parameters

Client Initialization Options
An optional dictionary of key-value pairs that influence the Filestack client.
Security
Object
{ policy: POLICY, signature: SIGNATURE }

If you have security enabled, you will need to initialize the client with a valid Filestack policy and signature in order to perform the requested call. This allows you to select who can and cannot perform certain actions on your site. Read more about security and how to generate policies and signatures

handle
the file to remove
Handle
String
'handle'

The Filestack handle that points to the file to remove. The format of the handle should be a string.