in hook_file_download there is just a parameter named uri. How can I get nid of the node that contains the file in uri?

For exmpale I have a file field in my content type.I create a node and add some files to file field. Now when this file is going to be downloaded, in hook_file_download I want to get nid of the file.How?

1 Answer 1


If this is an file attached through a file or image field, you can instead implement hook_file_download_access(), which gives you the $field, $entity_type and $entity to which the file belongs.

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.