Add an option to keep the file NAME but update the PATH and create a redirect to the new location

Created on 28 May 2025, 7 days ago

Problem/Motivation

Replacing a static file exactly is fraught due to multiple levels of caches, as evidenced by the "Important Caching Details" section on the module page β†’ and by numerous πŸ“Œ Make the overwrite original file description more user friendly Needs work comments πŸ“Œ Make the overwrite original file description more user friendly Needs work on improving the form help text πŸ“Œ Make the overwrite original file description more user friendly Needs work . It turned out for one of our clients the perfect compromise is to keep the file name but update the file path.

Same name, new path, plus redirect is better because people's browsers (etc) are more likely to have cached the PDF file (treated as a static asset) than the page, so having the page link to a new file path is an advantage in that situation. Adding a redirect helps people with the old direct link also get the new file.

Although it seems no file/media module takes this approach, regular Drupal Redirect module β†’ redirects do work for regular static sites/default/files (or equivalent) located files.

Proposed resolution

Add a radio button to provide this option "Use the file name from the replacement file at a unique file path, redirecting from old path to new". (And an administrative option to enable it or not, probably on a field level.)
Use the configured filepath for the new file (which may already include date tokens)
If the new filepath is not different from the old, add a subfolder using either a version ID or a timestamp to ensure it is unique.
Create the redirect (if Redirect module is enabled).

Remaining tasks

Decide if this can be a feature request in the main module, could be a submodule, or should be a separate module.

User interface changes

An additional radio button added to what gets decided in πŸ“Œ Make the overwrite original file description more user friendly Needs work

API changes

Data model changes

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

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

Comments & Activities

  • Issue created by @mlncn
  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    That's an interesting solution, but adds a good amount of complexity around generating the new directory structure. I don't really understand why it's important to have the same filename? Why not just append a unique number to the end of the file, delete the original, then add a redirect from the original? That's much less complicated. The client is that insistent that the filename be unchanged?

  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    The part that is important to them is that the file when people save it has the same name, and that is the part determined by the filename but not the path.

    Oh dear, i had hoped updating the directory would not be that difficult! (To be clear, i am planning to work on this but definitely hoping for feedback on technical implementation and of course especially if it is a feature, submodule, or separate module.)

    The 95% or so use case would be met by pretty much the default setup of a media entity with a file path that includes the date (`2025-05-28`) so if that simplifies things particularly i would do that, or even cover 99.999% of cases by include the time or just use a timestamp as the subdirectory. Media Entity File Replace has the best UX for the concept, and the crucial ability to upload a replacement without deleting the other first so there is the potential to do this redirect idea.

Production build 0.71.5 2024