Asset replacement, filenames and MIME type

I recently created an issue:

and followed that up with a PR:

Now there is a problem remaining that needs a decision to be solved reliably:

There needs to be a decision whether to prohibit the replacement for non-matching mime-types or whether to change the file extension on-the-fly.

(see BUGFIX: Use media type of new resource during asset replacement by kdambekalns · Pull Request #3366 · neos/neos-development-collection · GitHub)

What should we do when an editor replaces a resource with a new one having a different MIME type than before?
  • prohibit replacements
  • change file extension
  • do nothing

0 voters

Wouldn’t that mean that I can replace an image by a pdf, potentially breaking node properties that only support images?

It would be nice to be able to replace a png logo/icon by a svg version for example.

Yep, there are definitely some valid cases and many invalid cases for this…

Use cases exist, and my fix makes sure the MIME type in the database is correctly set. But a webserver using the file extension to determine the MIME type is (still) fooled by this, leading to errors.

The main question probably is: Does changing the extension break the expectation of “keep the existing filename”?

It’s certainly nice to be able to replace images, but I would suggest a different process for this.
Instead of saying “this png is now a svg” (or even a pdf) we could provide a better “usages” view that allows for (batch) updating properties of affected nodes for example.
This way the node type validation would still be respected and you’d have more control over it.

Replacing the asset itself feels a bit like changing a user entity completely while keeping its id :slight_smile:

One thing to remember: currently when the redirecthandler is installed it will also create a redirect if “keep the existing filename” is not set. When we still change the extension if it’s set, then we also have to adjust the redirect creation behaviour for that case.

IMO the most pragmatic thing is doing exactly that.
That we create a special view to replace assets sounds too far into the future :wink:

Ok, changing the extension it is…