phpframeworkstypo3typo3-flow

Are TYPO3 Flow Resources allowed with no ending?


we use the TYPO3 Flow 2.3 integrated Resource object to upload any kind of files in our project. The definition in our File object is:

/**
 * @var \TYPO3\Flow\Resource\Resource
 * @ORM\ManyToOne
 */
protected $originalresource;

And the fluid call goes like:

<a class="filelink" data-icon="{file.filetype}" href="{f:uri.resource(resource: file.originalresource)}" target="_blank">{file.name}</a>

Everything in this constellation works fine until a user uploads a file without ending like hosts. The server says Not Found in the regular Apache error style. Are files without endings supported or not? Why does this happen?

The Setting is:

TYPO3:
  Flow:  
    resource:
      storages:
        defaultPersistentResourcesStorage:
          storage: 'TYPO3\Flow\Resource\Storage\WritableFileSystemStorage'
          storageOptions:
            path: '%FLOW_PATH_DATA%Persistent/Resources/'
      targets:
        localWebDirectoryPersistentResourcesTarget:
          target: 'TYPO3\Flow\Resource\Target\FileSystemSymlinkTarget'
          targetOptions:
            path: '%FLOW_PATH_WEB%_Resources/Persistent/'
            baseUri: '_Resources/Persistent/'

And the created symbolic link for the hosts file in _Resources/Persistent/ is named with the hash and then a dot without file ending pointing the the actual file. The actual file exists.


Solution

  • It's a bug and you can report it here: https://jira.neos.io/

    In Flow 3.x it works fine, but there were major changes with resource management.

    Adding one line to Web/.htaccess should solve the problem, but I can't tell it's best solution.

    # Perform rewriting of persistent resource files
    RewriteRule ^(_Resources/Persistent/.{40})/.+(\..+) $1$2 [L]
    
    # Add this line - consider security
    RewriteRule ^(_Resources/Persistent/.{40})/.+ $1. [L]
    

    And answer why it happens - persistent resources are stored by default in Data/Persistent/Resources/<hash> and in you have symlink there from Web/_Resources/Persistent/<hash>.extension. So standard symlink looks like that:

    0c73666545d393d3d2d6b5a2039dceab56fb3aa2.txt -> /www/FLOW/23/Data/Persistent/Resources/0c73666545d393d3d2d6b5a2039dceab56fb3aa2
    

    If file has no extension there is just dot at the end

    a94a8fe5ccb19ba61c4c0873d391e987982fbbd3. -> /www/FLOW/23/Data/Persistent/Resources/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
    

    So in fact link returned by ResourceViewHelper (FileSystemPublishingTarget) is correct, but first rewrite rule above requires extension. Adding second one you catch files without extension and just add . at the end to match correct symlink with hash and dot at the end.