TYPO3 Flow Resources 是否允许没有结尾?
Are TYPO3 Flow Resources allowed with no ending?
我们使用 TYPO3 Flow 2.3 集成资源对象上传我们项目中的任何类型的文件。我们的 File
对象中的定义是:
/**
* @var \TYPO3\Flow\Resource\Resource
* @ORM\ManyToOne
*/
protected $originalresource;
流畅的调用是这样的:
<a class="filelink" data-icon="{file.filetype}" href="{f:uri.resource(resource: file.originalresource)}" target="_blank">{file.name}</a>
在用户上传没有像 hosts
这样结尾的文件之前,此星座中的一切都正常工作。服务器以常规 Apache 错误样式显示 Not Found
。是否支持没有结尾的文件?为什么会这样?
设置为:
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/'
并且为 _Resources/Persistent/
中的 hosts
文件创建的符号 link 以哈希命名,然后是一个没有文件结尾的点指向实际文件。实际文件存在。
这是一个错误,您可以在此处报告:https://jira.neos.io/
在 Flow 3.x 中工作正常,但资源管理发生了重大变化。
在 Web/.htaccess 中添加一行应该可以解决问题,但我不知道这是最佳解决方案。
# Perform rewriting of persistent resource files
RewriteRule ^(_Resources/Persistent/.{40})/.+(\..+) [L]
# Add this line - consider security
RewriteRule ^(_Resources/Persistent/.{40})/.+ . [L]
并回答它发生的原因 - 默认情况下,永久资源存储在 Data/Persistent/Resources/<hash>
中,并且您在 Web/_Resources/Persistent/<hash>.extension
中有 symlink。所以标准的 symlink 看起来像这样:
0c73666545d393d3d2d6b5a2039dceab56fb3aa2.txt -> /www/FLOW/23/Data/Persistent/Resources/0c73666545d393d3d2d6b5a2039dceab56fb3aa2
如果文件没有扩展名,末尾只有点
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3. -> /www/FLOW/23/Data/Persistent/Resources/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
所以实际上ResourceViewHelper(FileSystemPublishingTarget)返回的link是正确的,但是上面的第一个重写规则需要扩展。添加第二个你捕获没有扩展名的文件,只需添加 .在末尾匹配正确的 symlink 和末尾的散列和点。
我们使用 TYPO3 Flow 2.3 集成资源对象上传我们项目中的任何类型的文件。我们的 File
对象中的定义是:
/**
* @var \TYPO3\Flow\Resource\Resource
* @ORM\ManyToOne
*/
protected $originalresource;
流畅的调用是这样的:
<a class="filelink" data-icon="{file.filetype}" href="{f:uri.resource(resource: file.originalresource)}" target="_blank">{file.name}</a>
在用户上传没有像 hosts
这样结尾的文件之前,此星座中的一切都正常工作。服务器以常规 Apache 错误样式显示 Not Found
。是否支持没有结尾的文件?为什么会这样?
设置为:
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/'
并且为 _Resources/Persistent/
中的 hosts
文件创建的符号 link 以哈希命名,然后是一个没有文件结尾的点指向实际文件。实际文件存在。
这是一个错误,您可以在此处报告:https://jira.neos.io/
在 Flow 3.x 中工作正常,但资源管理发生了重大变化。
在 Web/.htaccess 中添加一行应该可以解决问题,但我不知道这是最佳解决方案。
# Perform rewriting of persistent resource files
RewriteRule ^(_Resources/Persistent/.{40})/.+(\..+) [L]
# Add this line - consider security
RewriteRule ^(_Resources/Persistent/.{40})/.+ . [L]
并回答它发生的原因 - 默认情况下,永久资源存储在 Data/Persistent/Resources/<hash>
中,并且您在 Web/_Resources/Persistent/<hash>.extension
中有 symlink。所以标准的 symlink 看起来像这样:
0c73666545d393d3d2d6b5a2039dceab56fb3aa2.txt -> /www/FLOW/23/Data/Persistent/Resources/0c73666545d393d3d2d6b5a2039dceab56fb3aa2
如果文件没有扩展名,末尾只有点
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3. -> /www/FLOW/23/Data/Persistent/Resources/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
所以实际上ResourceViewHelper(FileSystemPublishingTarget)返回的link是正确的,但是上面的第一个重写规则需要扩展。添加第二个你捕获没有扩展名的文件,只需添加 .在末尾匹配正确的 symlink 和末尾的散列和点。