---
title: "Secured Links"
manual: "secure_downloads"
version: "main"
permalink: "https://docs.typo3.org/permalink/leuchtfeuer/secure-downloads:developer-securedlinks@main"
source: "Developer/SecuredLinks/Index.rst"
rendered: "2026-09-22T10:54:01+00:00"
---

# Secured Links {#developer-securedlinks}

Following examples clarifies, how to retrieve secured links from different data type sources.

## File Object {#developer-securedlinks-fileobject}

Instance of `TYPO3CMSCoreResourceFile` given:

```php
/** @var \TYPO3\CMS\Core\Resource\File $file */
$securedUrl = $file->getPublicUrl();
```

## File Reference {#developer-securedlinks-filereference}

Instance of `TYPO3CMSCoreResourceFileReference` given:

```php
/** @var \TYPO3\CMS\Core\Resource\FileReference $fileReference */
$securedUrl = $fileReference->getPublicUrl();
```

## Fluid Templates {#developer-securedlinks-fluidtemplates}

Getting secured links within a fluid template is a no-brainer; you don't have to pay attention to anything here:

```html
<f:image image="{image}" class="img-fluid img-thumbnail" />
<f:image image="{image}" treatIdAsReference="TRUE" class="img-fluid img-thumbnail" />
<img src="{image.publicUrl}" class="img-fluid img-thumbnail" />
```

## API {#developer-securedlinks-api}

Get a link that is only valid for user `29`, with user group `12`, is generated on page `89` and expires on `2022/05/08`:

```php
$publicUrl = '/fileadmin/secured/invoice.pdf';
$secureDownloadService = GeneralUtility::makeInstance(SecureDownloadService::class);

if ($secureDownloadService->pathShouldBeSecured($publicUrl)) {
    $securedUrl = GeneralUtility::makeInstance(SecureLinkFactory::class)
        ->withResourceUri(rawurldecode($publicUrl))
        ->withUser(29)
        ->withPage(89)
        ->withGroups([12])
        ->withTimeout(1659650400)
        ->getUrl();
}
```
