0

Media module provides a generic.png file that it copies into /sites/default/media-icons/generic. That file is used on my site ~300 times, but I'd like to replace it with another PNG. Is it possible to replace the actual file that is associated with that file entity? Ideally I'd keep the generic.png name, but I can use an updated file name if needed.

I've tried simply replacing the file in /sites/default but that had no effect.

  • Replacing the file in the file system is all you need to do. But if there are image styles associated with the file, you'll need to flush those styles so that they can be regenerated with the new image source – Clive Jun 19 at 6:40
  • Bizarre, just replacing the file on our test server worked, but it isn't having any effect on prod. There must be something else going on – Mrweiner Jun 19 at 7:03
  • Probably varnish/another proxy has it cached – Clive Jun 19 at 7:29
  • @Clive – Is this a question about the fid then? I'd say no. The mentioned file has no fid, does it? As far as I know simply replacing files that already have a fid and meta information saved in the database won't simply work. – leymannx Jun 25 at 21:01
0

As @clive noted in the comments, all that is needed is to replace the file itself. We were having some other server issues that were causing the change not to show up. You may need to flush your image styles in order for those to pick up the new image, though.

  • Is this really a question about the file ID then as the question title suggests? The mentioned file does not have a file ID, or does it? I'm asking since normally simply replacing the file physically won't be sufficient. If the file size or other file meta data changes, Drupal often refuses to render the file anymore. – leymannx Jun 26 at 16:17
  • @leymannx I cannot speak to the metadata specifically, but I was indeed able to maintain use of the same file entity while changing the file associated with it. – Mrweiner Jun 26 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.