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 filepicker.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

<script src="https://api.filestackapi.com/filestack.js"></script>
<script type="text/javascript">
  filepicker.setKey("your_API_KEY");
  filepicker.remove(Blob, security_options, onSuccess(Blob){}, onError(FPError){});
</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 - Remove a file

Create a file, remove the file, then confirm removal
console.log("Storing..."); filepicker.store( "Test text", function(new_blob) { console.log(JSON.stringify(new_blob)); var cdn_url = new_blob.url; console.log("Removing..."); filepicker.remove( new_blob, { policy: 'eyJleHBpcnkiOjE2ODgxMzkwNTJ9', signature: '5f66059fcacd65298ea55f66bf005f73688534632f20e77c5b1f0ac69d1c0286' }, function(new_blob) { console.log("Removed"); filepicker.remove( cdn_url, function(FPError) { console.log(FPError.toString()); }, function(metadata) { console.log("removing file again (expected result: error 171)..."); console.log(JSON.stringify(metadata)); } ); } ); } );
blob
the file to remove
Blob
Blob
{blob}

A Blob pointing to the file you would like to remove. This can also be a Filestack URL. Note that if the file was pulled from a user's cloud storage service (Dropbox, etc.), the remove call will not delete the file from the user's cloud storage, but if the Blob was generated by a store operation the remove call will delete the stored copy.

security_options
An optional dictionary of key-value pairs that configures the remove call.
Security
String
{policy: POLICY, signature: SIGNATURE}

If you have security enabled for your API key you will need to include a valid Filestack security policy and signature in order to perform the remove call. This allows you to prevent the unauthorized removal of your files. Read more about security and how to generate policies and signatures.

onSuccess
The function to call if the remove is successful. There are no parameters passed to this callback.

onError
The function to call if there is an error when removing the file.

Possible error codes on the FPError:

171 The file cannot be found, and may have already been deleted
172 The underlying content store could not be reached

Sample response

{
  "code":101
}