Secure Asset Download is a simple Craft CMS plugin allowing you, from your templates, to generate download URLs for specified assets that are only available to certain users/groups
- Copy the
secureassetdownload
directory into yourcraft/plugins
directory - Navigate to Settings > Plugins in the Craft CP
- Click on the Install button next to Secure Asset Download
- Set secret key in plugin settings by clicking Secure Asset Download
- Use
{{ craft.secureAssetDownload.getUrl(options) }}
to generate secure URL (see usage below)
Encryption Key: Secret key used when encrypting the URLs
asset is the only required option. If no other options are set any logged in user will be able to access generated URLs. Admins have access to all generated URLs regardless of options
{
asset: id or AssetFileModel, // e.g 14 or craft.asset.id(23).first()
userId: id or array of user ids, // e.g. 6 or [ 17, 28, 30 ]
userGroupId: id or array of user group ids, // e.g. 3 or [ 1, 99, 76 ]
forceDownload: true or false, // Optional field to force the download rather than opening in the tab (default: true)
}
note: Options are AND logic
{% set options = {
asset: 17
} %}
{% set options = {
asset: 17,
userGroupId: 2
} %}
{% set options = {
asset: 17,
userGroupId: [ 2, 6 ]
} %}
{% set options = {
asset: 17,
userId: [ 46, 86 ]
} %}
{% set options = {
asset: 17,
forceDownload: false
} %}
Followed by
{% set url = craft.secureAssetDownload.getUrl(options) %}
<a href="{{ url }}">Download me</a><br><br>