The /file/filter Robot

Transloadit lets you reject, or direct files against different encoding Steps.

The /file/filter Robot is a gatekeeper that can direct files to different encoding Steps based on your conditions.

Parameters

Name Type Default Description
accepts Array of Arrays [] Files that match at least one requirement will be accepted, or declined otherwise. Example:
[['${file.mime}', '=', 'image/gif']].
If the condition_type parameter is set to "and ", then all requirements must match for the file to be accepted.
declines Array of Arrays [] Files that match at least one requirement will be declined, or accepted otherwise. Example:
[['${file.size}','>','1024']].
If the condition_type parameter is set to "and ", then all requirements must match for the file to be declined.
condition_type String "or" Specifies the condition type according to which the members of the accepts or declines arrays should be evaluated. Can be "or" or "and".
error_on_decline Boolean false If this is set to true and one or more files are declined, the Assembly will be stopped and marked with an error.
error_msg String "One of your files was declined" This is the error message shown to your users (such as by the jQuery SDK) when a file is declined and error_on_decline is set to true.

Live demos

Our /file/filter Robot can be used in combination with other Robots, to create powerful workflows unique to your use case.
Here are a few example scenarios, and the required the Assembly Instructions to implement them.
You can also try demos of these examples right here, live on our website.

Transparently extract uploaded archives

{
  "steps": {
    "archives_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "accepts": [["${file.mime}", "regex", "application/(rar|x-7z-compressed|x-cab|x-cpio|x-debian-package|x-gtar-compressed|x-gzip|x-lzh|x-redhat-package-manager|x-tar|zip)"]],
      "error_on_decline": false
    },
    "nonarchives_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "declines": [["${file.mime}", "regex", "application/(rar|x-7z-compressed|x-cab|x-cpio|x-debian-package|x-gtar-compressed|x-gzip|x-lzh|x-redhat-package-manager|x-tar|zip)"]],
      "error_on_decline": false
    },
    "extracted": {
      "use": ["archives_filtered"],
      "robot": "/file/decompress",
      "result": true
    },
    "ipad_encoded": {
      "use": ["nonarchives_filtered", "extracted"],
      "robot": "/video/encode",
      "result": true,
      "ffmpeg_stack": "v2.2.3",
      "preset": "ipad-high"
    },
    "web_encoded": {
      "use": ["nonarchives_filtered", "extracted"],
      "robot": "/video/encode",
      "result": true,
      "ffmpeg_stack": "v2.2.3",
      "preset": "webm"
    },
    "exported": {
      "use": ["nonarchives_filtered", "archives_filtered", "extracted", "ipad_encoded", "web_encoded", ":original"],
      "robot": "/s3/store",
      "bucket": "demos.transloadit.com",
      "bucket_region": "us-east-1",
      "key": "YOUR_AWS_KEY",
      "secret": "YOUR_AWS_SECRET"
    }
  }
}

Filter out videos that are larger than 20MB or longer than 5 minutes

{
  "steps": {
    "files_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "declines": [["${file.size}", ">", "20971520"],["${file.meta.duration}", ">=", "300"]],
      "error_on_decline": true
    },
    "exported": {
      "use": ["files_filtered", ":original"],
      "robot": "/s3/store",
      "bucket": "demos.transloadit.com",
      "bucket_region": "us-east-1",
      "key": "YOUR_AWS_KEY",
      "secret": "YOUR_AWS_SECRET"
    }
  }
}

Filter out all audio files with a bit rate lower than 64K

{
  "steps": {
    "files_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "declines": [["${file.meta.audio_bitrate}", "<", "64000"]]
    },
    "exported": {
      "use": ["files_filtered", ":original"],
      "robot": "/s3/store",
      "bucket": "demos.transloadit.com",
      "bucket_region": "us-east-1",
      "key": "YOUR_AWS_KEY",
      "secret": "YOUR_AWS_SECRET"
    }
  }
}

Filter out files that are smaller than 1KB

{
  "steps": {
    "files_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "accepts": [["${file.size}", ">=", "1024"]]
    },
    "exported": {
      "use": ["files_filtered", ":original"],
      "robot": "/s3/store",
      "bucket": "demos.transloadit.com",
      "bucket_region": "us-east-1",
      "key": "YOUR_AWS_KEY",
      "secret": "YOUR_AWS_SECRET"
    }
  }
}

Filter out anything other than image files

{
  "steps": {
    "files_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "accepts": [["${file.mime}", "regex", "image"]],
      "error_on_decline": true
    },
    "exported": {
      "use": ["files_filtered", ":original"],
      "robot": "/s3/store",
      "bucket": "demos.transloadit.com",
      "bucket_region": "us-east-1",
      "key": "YOUR_AWS_KEY",
      "secret": "YOUR_AWS_SECRET"
    }
  }
}

Filter out anything other than video or image files

{
  "steps": {
    "files_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "accepts": [["${file.mime}", "regex", "image"],["${file.mime}", "regex", "video"]],
      "error_on_decline": true
    },
    "exported": {
      "use": ["files_filtered", ":original"],
      "robot": "/s3/store",
      "bucket": "demos.transloadit.com",
      "bucket_region": "us-east-1",
      "key": "YOUR_AWS_KEY",
      "secret": "YOUR_AWS_SECRET"
    }
  }
}

Only resize larger images when resizing files

{
  "steps": {
    "large_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "accepts": [["${file.meta.width}", ">", "2048"],["${file.meta.height}", ">", "2048"]],
      "condition_type": "or"
    },
    "smaller_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "accepts": [["${file.meta.width}", "<=", "2048"],["${file.meta.height}", "<=", "2048"]],
      "condition_type": "or"
    },
    "large_resized": {
      "use": ["large_filtered"],
      "robot": "/image/resize",
      "result": true,
      "height": 2048,
      "imagemagick_stack": "v1.0.0",
      "resize_strategy": "fit",
      "width": 2048
    },
    "smaller_resized": {
      "use": ["smaller_filtered"],
      "robot": "/image/resize",
      "result": true,
      "height": "${file.meta.height}",
      "imagemagick_stack": "v1.0.0",
      "resize_strategy": "fit",
      "width": "${file.meta.width}"
    },
    "optimized": {
      "use": ["smaller_resized", "large_resized"],
      "robot": "/image/optimize",
      "result": true
    },
    "exported": {
      "use": [":original", "large_filtered", "large_resized", "optimized", "smaller_filtered", "smaller_resized"],
      "robot": "/s3/store",
      "bucket": "demos.transloadit.com",
      "bucket_region": "us-east-1",
      "key": "YOUR_AWS_KEY",
      "secret": "YOUR_AWS_SECRET"
    }
  }
}

Reject videos that do not have an audio track

{
  "steps": {
    "nomute_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "declines": [["${file.meta.audio_bitrate}", "=", ""]],
      "error_on_decline": true
    },
    "iphone_encoded": {
      "use": [":original"],
      "robot": "/video/encode",
      "result": true,
      "ffmpeg_stack": "v2.2.3",
      "preset": "iphone"
    },
    "exported": {
      "use": ["iphone_encoded", ":original"],
      "robot": "/s3/store",
      "bucket": "demos.transloadit.com",
      "bucket_region": "us-east-1",
      "key": "YOUR_AWS_KEY",
      "secret": "YOUR_AWS_SECRET"
    }
  }
}

Properly preserve transparency across image types

{
  "steps": {
    "nontransparent_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "accepts": [["${file.mime}", "=", "image/jpeg"],["${file.mime}", "=", "image/jpg"]],
      "error_on_decline": false
    },
    "maybetransparent_filtered": {
      "use": [":original"],
      "robot": "/file/filter",
      "result": true,
      "declines": [["${file.mime}", "=", "image/jpeg"],["${file.mime}", "=", "image/jpg"]],
      "error_on_decline": false
    },
    "nontransparent_resized": {
      "use": ["nontransparent_filtered"],
      "robot": "/image/resize",
      "result": true,
      "height": 300,
      "imagemagick_stack": "v1.0.0",
      "resize_strategy": "fit",
      "width": 400
    },
    "maybetransparent_resized": {
      "use": ["maybetransparent_filtered"],
      "robot": "/image/resize",
      "result": true,
      "background": "none",
      "height": 300,
      "imagemagick_stack": "v1.0.0",
      "resize_strategy": "fit",
      "width": 400
    },
    "exported": {
      "use": ["nontransparent_filtered", "maybetransparent_filtered", "nontransparent_resized", "maybetransparent_resized", ":original"],
      "robot": "/s3/store",
      "bucket": "demos.transloadit.com",
      "bucket_region": "us-east-1",
      "key": "YOUR_AWS_KEY",
      "secret": "YOUR_AWS_SECRET"
    }
  }
}

Our /file/filter robot blog posts

Over the years we wrote the following posts about Our /file/filter robot on our blog:

Did you know?

You can easily combine Robots to create powerful workflows, unique to your business.
This is the power of Transloadit.