I would like to protect private files with password in a content. For example, I created a content with some files, this field "Protected files" uses private filesystem.

I would like to protect these files in order to anonymous users can download these ones with a correct password.

How can I achieve this in Drupal 8?

  • 2
    An anonymous user with a password is an authenticated user, isn't it? Looking at it that way, everything's already built in to be able to do that with permissions – Clive Jan 21 at 15:40
  • I mean, I would define a global password for protected files like other modules do for nodes. – asrob Jan 21 at 15:45
  • 3
    If it was me I'd be considering whether that's really worth the effort - a global password is pretty much as good as no password. But either way, I suspect you could solve it using hook_file_download and adding a custom authorisation header – Clive Jan 21 at 15:48
  • Does this go the direction you need: drupal.org/project/protected_file? Alternatively, using webforms is a decent way to protect content. Webforms would allow you to ask for emails, passwords, anything. And you could utilize a form submit hook() or such to deliver, or direct to, your protected content. I recently worked on a D7 project where we coupled webforms with view modes asking users to enter their email to download content. – Prestosaurus Jan 22 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.