# Disabling media generation for specific files

**URL:** <https://forum.getkirby.com/t/disabling-media-generation-for-specific-files/13010>\
**Category:** Questions\
**Tags:** v3\
**Created:** [February 22, 2019, 5:40am UTC](https://forum.getkirby.com/t/disabling-media-generation-for-specific-files/13010 "2019-02-22T05:40:35Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pedroborges](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pedroborges/32/7038_2.png) [@pedroborges](https://forum.getkirby.com/u/pedroborges)\
**Post date:** [February 22, 2019, 4:10pm UTC](https://forum.getkirby.com/t/disabling-media-generation-for-specific-files/13010/2 "2019-02-22T16:10:23Z")

</div>

Are you making download links available for restricted files with `$file->url()`? Files get copied to the media folder only when the URL returned by the `url()` method is accessed in the browser.

I suggest you to create a custom file method to generate a URL for restricted files instead of using the default `$file->url()`. Then point those files to a custom route from where you could handle the authorization logic or token validation. Here is a simple example:

```php
<?php // site/config/config.php

return [
  'routes' => [
    [
      'pattern' => 'restricted/(:any)',
      'action' => function ($hash) {
        // validate request

        if ($file = site()->index()->files()->findBy('hash', $hash)) {
          return Response::download($file->root(), 'new-filename.pdf');
        }

        return site()->errorPage();
      }
    ],
  ],
];

```

---

_[View the full topic](https://forum.getkirby.com/t/disabling-media-generation-for-specific-files/13010)._
