Get File Metadata

Once you get a file via filepicker.pick, filepicker.store, filepicker.convert, or any of the other calls, you can use the filepicker.stat call to get more detailed metadata about the file.

Syntax

<script src="https://api.filestackapi.com/filestack.js"></script>
<script type="text/javascript">
  filepicker.setKey("your_API_KEY");
  filepicker.stat(input, [options], onSuccess(metadata){}, onError(FPError){});
</script>

Example Stat Code - Return the default metadata Filestack stores for a file

Fetch the default Filestack metadata for a file
/*Blob from a previous pick, etc.*/ var blob = { url: 'https://www.filestackapi.com/api/file/9BWnyKPBQI23ukbT7sZA' }; console.log("Loading metadata..."); filepicker.stat( blob, function(metadata){ console.log(JSON.stringify(metadata)); } );

Example Stat Code - Get the pixel dimensions of an image file

Fetch the pixel height and width of a Filestack image
filepicker.setKey("AhTgLagciQByzXpFGRI0Az"); /*Blob from a previous pick, etc.*/ var blob = { url: 'https://www.filestackapi.com/api/file/9BWnyKPBQI23ukbT7sZA' }; console.log("Loading image dimensions..."); filepicker.stat( blob, { width: true, height: true }, function(metadata){ console.log(JSON.stringify(metadata)); } );

Parameters

blob
the object to return metadata for
blob
Blob
{blob}

A Blob pointing to the file you'd like to get information from. If you have a DOM File object or raw data, you can use the filepicker.store call to first generate a Blob

options
An optional dictionary of key-value pairs that specify what metadata you want back. By default, we return any metadata we get without having to run over the contents of the file (currently: size, mimetype, filename, uploaded, writeable, location, path, container).
size
Boolean
{size: true}

Specify that you want the size of the file returned as a number in bytes.

mimetype
Boolean
{mimetype: true}

Specify that you want the mimetype of the file returned as a string.

filename
Boolean
{filename: true}

Specify that you want the name of the file returned as a string.

width
Boolean
{width: true}

Specify that you want the width of the image returned as an integer in pixels. If the file is not an image, width is set to null.

height
Boolean
{height: true}

Specify that you want the height of the image returned as an integer in pixels. If the file is not an image, height is set to null.

uploaded
Boolean
{uploaded: true}

Specify that you want the timestamp of when the file was uploaded to Filestack, as a javascript Date object

writeable
Boolean
{writeable: true}

Specify that you want to know whether the file is writeable. The value will be true or false.

cloud
Boolean
{cloud: true}

Applies to files uploaded from cloud drives using filepicker.pick only. Specifies that you want to see what metadata is available about the file where it is stored, such as original creation date and caption (if the file was picked from Instagram or Facebook).

source url
Boolean
{source_url: true}

If your file was selected via the image search or URL search service in the picker using filepicker.pick() and the image was not cropped via the crop interface, then you can request the original url of the file.

Hashing Algorithms

Note:You can specify more than one algorithm in your code, but We will return only one hash based on the lexicographical order of the hashing algorithm names. So for instance, if you specify sha-256 and md5 in the same request, we will compute and return only the MD5 hash.

MD5 Hash
Boolean
{md5: true}

Specify that you want the md5 hash of the file returned as a string.

SHA-1 Hash
Boolean
{sha1: true}

Specify that you want the SHA-1 hash of the file returned as a string.

SHA-224 Hash
Boolean
{sha224: true}

Specify that you want the SHA-224 hash of the file returned as a string

SHA-256 Hash
Boolean
{sha256: true}

Specify that you want the SHA-256 hash of the file returned as a string

SHA-384 Hash
Boolean
{sha384: true}

Specify that you want the SHA-384 hash of the file returned as a string

SHA-512 Hash
Boolean
{sha512: true}

Specify that you want the SHA-512 hash of the file returned as a string

Storage and Security

Storage Location
Boolean
{location: true}

Specify that you want to know the storage location (S3, etc.) of a stored file, if available, as a string

Storage Path
Boolean
{path: true}

Specify that you want to know the storage path of a stored file, if available, as a string.

Storage Container
Boolean
{container: true}

Specify that you want to know the storage container of a stored file, if available, as a string

Security
String
{policy: POLICY, signature: SIGNATURE}

If you have security enabled, you'll need to have 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

EXIF
Boolean
{exif: true}

If you would like to view the exif metadata of a photo as a JSON object, the request must be accompanied by a valid security policy and signature. Without the policy and signature, the EXIF data will not be returned. This is required because EXIF metadata can include personally identifiable information.

onSuccess
The function to call with the requested metadata of the inputted file.

We return a JSON object containing the requested metadata

Sample response

{"width":180,"height":180}
onError
The function to call if there is an error when reading the metadata of the file.

Possible error codes on the FPError:

161 The file cannot be found
162 Error fetching metadata

Sample response

{
  "code":101
}