Some modules need to react on private file downloads, e.g. to implement download counters or to set flags for nodes containing files. Since Drupal 7.29 (see https://www.drupal.org/drupal-7.29-release-notes ) the only way to do this is to override page callback for "system/files" menu item.

I suggest to add hook_file_transfer() and invoke it from file_transfer() function to allow other modules to react on private file downloads (it will also be invoked on image derivative creation, but modules will be able to look at uri scheme of the file).

CommentFileSizeAuthor
#1 2500949-hook_file_transfer-d7-1.patch510 bytesmaximpodorov

Comments

maximpodorov’s picture

Status: Active » Needs review
StatusFileSize
new510 bytes

The first patch (without API documentation). If adding this hook is acceptable, API documentation can be added in subsequent patches.

cilefen’s picture

Just to be thorough, what would be the equivalent in Drupal 8? file_transfer was removed in favor of BinaryFileResponse. It is probably an Event.

dave reid’s picture

Status: Needs review » Closed (duplicate)