TYPO3CMS-Reference-CoreApi icon indicating copy to clipboard operation
TYPO3CMS-Reference-CoreApi copied to clipboard

Document $GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['fileExtensionToMimeType']?

Open sypets opened this issue 1 year ago • 2 comments

Current behavior

The option $GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['fileExtensionToMimeType'] exists. It is used in FileInfo::getMimeType.

This option is listed in core/Configuration/DefaultConfiguration.php, but cannot be configured in the BE module "Global Configuration".

It is not listed on the SYS page: https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/Configuration/Typo3ConfVars/SYS.html

Expected behavior/output

  • Document this option as well.
  • explain why it is recommended to only set this if automatic detection does not work

Links

Additional context

There are some caveats to consider, so it might be useful to have more information about this online.

DefaultConfiguration.php explains in a comment:

// Static mapping for file extensions to mime types. // In special cases the mime type is not detected correctly. // Use this array only if the automatic detection does not work correct!

But it does not explain why. Fact is that fileExtensionToMimeType takes precedence over automatic detection in FileInfo::getMimeType. So if more file types are configured there, this will result in an automatic mapping from file extension to mimetype. This would result in wrong mimetype if editor uploads files with wrong file ending.

If files are uploaded with the wrong mimetypes, scaling might not work correctly. I noticed this in v11 because more mappings were defined in fileExtensionToMimeType (due to secure_downloads, which configures this by default) and this resulted in wrongly detected mimetypes because editors uploaded files with wrong file ending. This results in processed files with size 0 which will not automatically get removed, even if the file is renamed later.

So, TYPO3 uses a good default (svg, youtube, vimeo) and you shouldn't really change it, except for in the changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/7.2/Feature-66445-AddFileExtensionToMimeTypeMapping.html it is recommended to exclude svg unless automatic detection fails.

On the other hand, automatic detection probably has a small load and performance impact, especially, since this is called multiple times when handling files.

sypets avatar Dec 10 '23 08:12 sypets

A related question is if generated files with size 0 should be saved at all.

DavidBruchmann avatar Dec 10 '23 12:12 DavidBruchmann

As there is a changelog entry this is public API. But we should emphasize that it should be used only in very special cases. "youtube" and "vimeo" are special cases, as TYPO3 uses them in FAL for the special youtube/vimeo files - they are not official defined by IANA - AFAIK.

brotkrueml avatar Dec 10 '23 14:12 brotkrueml