Loading...


Related Products


Date Published: June 26, 2023

Replace uploaded files with a new file version and have the path and filename remain the same

Issue

Deleting a file and replacing it with a new version while retaining the same filename does not work, as the new version would automatically get a prefix (_0) attached to it each time a new version is uploaded (for example: filename_0.pdf; filename_1.pdf, etc.).

Resolution

Use the Media Entity Download module. It allows linking content to media/{media_id}/download no matter the filename.

Caveats:

  • Depending upon your site architecture and number of files using this strategy, there might be a performance impact since Drupal will be bootstraped to fetch and return the unique route
  • There is currently no integration with Pathauto

Option 2: Add Support for Renaming Files

There are two community modules which add this ability to Drupal. Either can be used:

The major caveat with this approach is that the outdated versions of the files can be stuck in one of several places Varnish, Acquia Edge, Platform CDN, or even an external CDN. To get around this one of the following modules can be used in conjunction with either of the above:

Additional Modules to Consider

The need for either of these approaches is usually only necessary on sites which may have a large number of files managed by a potentially large number of users. In this case, you may want to explore using one or both of the following modules as well. They have good track records of making files in Drupal easier to manage.

Cause

Drupal core doesn't currently support replacing uploaded files with the same filename.

Did not find what you were looking for?

If this content did not answer your questions, try searching or contacting our support team for further assistance.

Back to Section navigation