Module Description
Overview This simple modules provides a new path /document/[id] which redirects to the file source of a media entity.

For many media entities with file sources (like a "Document" media entity), you typically want to link users directly to the file source path. However, it's not considered a good practice to link to this direct path because if the file is replaced with a new one, the path with change, even if you upload a replacement file with the same name.

This module works around that problem by providing a new path /document/[id], where [id] id the ID of the media entity. Requests to this path will redirect to the actual file source path.

This allows you to "hide" the real file path in your links. If you ever need to replace the file upload with a new one, you don't need to worry about updating any links to that file.

This module also provides support for LinkIt, allowing you to create these /document/[id] links directly in CKEditor.

Setup/Configuration After this module is enabled, edit one of your existing media types that uses a file or image source field. You will see a checkbox "Expose access to file source via path /document/[id]" to enable the behavior for all media entities of that type.

LinkIt
This module ships with LinkIt "Matcher" called "Media: File Redirect". This is identical to the normal "Media" matcher, with two key differences:


* If you have canonical paths for media entities disabled, this matcher still works, whereas the normal "Media" matcher does not
* The URL that's returned by the LinkIt search field is /document/[id] instead of /media/[id]. Even if you have canonical paths enabled for media entities, this is helpful because it won't confuse your editors to see the /media/[id] path (many do not consider a file or document to be "media").

Similar Modules The Media Entity File Replace module allows editors to replace files and overwrite the original filename, thus negating the need to obscure the real path of the file.

The Media Entity Download module does something similar to Media Entity File Replace. It creates a dedicated "download" path, /media/[id]/download, which returns the file source as a direct download instead of redirecting to the file source URL.

The downside to such an approach is that Drupal acts as a proxy for serving up file assets, which takes up PHP resources. That may not be a big deal if there are not many documents and they are not extremely popular to download. It also forces your browser to download the file instead of possibly opening it directly in your browser

Project Usage
478
Creation Date
Changed Date
Security Covered
Covered By Security Advisory
Version Available
Production
Module Summary
This module provides a new path /document/[id] which redirects to the file source of a media entity, allowing you to hide the real file path in your links and easily replace files without updating links.
Data Name
media_entity_file_redirect

OPENAI CHATBOT

OPENAI CHATBOT

16:25:00
Generic Chatbot
Hi, I'm a Drupal module expert powered by OpenAI, answering your questions about the Drupal module ecosystem. How can I be helpful today? Please note that we will log your question.