Add support for private files

Created on 8 January 2025, 22 days ago

Problem/Motivation

It would be useful if this module could support private file storage, so that the unzipped files can be subject to Drupal's access control mechanisms.

Steps to reproduce

Add a zip file field to a content type, and specify the Upload Destination as "Private Files". (And configure the Private Files directory if necessary.) Upload a zipped file. The resulting unzipped files are not accessible to any users (not even administrator).

Proposed resolution

For files in the private storage directory to be accessible they need to be correctly set up as managed files. It seems that there will need to be an extra entity field to keep track of the unzipped files (e.g. field_unzipped_files), and for each of the unzipped files, there needs to be the following in the database:

  • An entry in the file_managed table
  • An entry in the file_usage table
  • An entry in a node__field_unzipped_files table

In outline, these can be set up using:

  • \Drupal\file\Entity\File::create(...)
  • \Drupal::service('file.usage')->add(...)
  • $entity->set('field_unzipped_file', $file);

Remaining tasks

Implement the code. Test.

User interface changes

none

API changes

none

Data model changes

none

Feature request
Status

Active

Version

1.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024