1

So I've uploaded a private file. It can be accessed like following:

http://drupal8.dev/system/files/2016-12/README.txt

How can I change how that file is accessed?

http://drupal8.dev/files/README.txt, etc.

2 Answers 2

0

This is a route in system.routing.yml:

system.private_file_download:
  path: '/system/files/{filepath}'
  defaults:
    _controller: 'Drupal\system\FileDownloadController::download'
  requirements:
    # Permissive regex to allow slashes in filepath see
    # http://symfony.com/doc/current/cookbook/routing/slash_in_parameter.html
    filepath: .+
    _access: 'TRUE'

You can change the path in a route subscriber.

Reference: https://www.drupal.org/docs/8/api/routing-system/altering-existing-routes-and-adding-new-routes-based-on-dynamic-ones

0

Assuming I understand the question: To the best of my knowledge, you cannot. For a file in the private file system, the file URL must be rendered on a page in order to be accessed. Redirects and rewrites won't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.