0

In my project, I am using headless Drupal with .Net on the front end.

I have to use private and encrypted file systems for the project requirements. The files which I am uploading through Drupal private file field from content type are accessible through URL, but as encrypted files aren't accessible through direct URL, I thought of copying the decrypted files from the encrypted folder to the private folder so they become accessible. Strangely, these files aren't accessible for authenticated users, who get access denied for this particular case.

I can't copy these files to the public folder as it is accessible to anonymous users too. So here I am facing two problems:

  • Is there any way to restrict public files(sites/default/files/*) to authenticated users only so that anonymous users can't view them? I tried the rewrite rules in the .htaccess file, but it isn't restricting the URL to particular users, and it redirects users to a private URL.
  • Is there any way to access the copied files from the private folder via URL?

These files aren't uploaded through Drupal private file field, but they are copied from the encrypted folder to the private folder through custom code.

1 Answer 1

-1

I would suggest using a Controller whose route parameter(s) can be used to specify the desired file. Then your controller (either directly or by delegating to another service) can access the file, decrypt it, then return the contents. The route that you define for your controller supports permissions, so you can easily apply access control.

Drupal console is a fantastic resource for generating Drupal assets, such as controllers. To generate a new controller with Drupal console: drupal generate:controller.

Your Answer

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

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