wwwision/form-securefileupload

带有示例和辅助工具的流程包,用于实现安全的表单上传

1.1.0 2021-10-20 10:19 UTC

This package is auto-updated.

Last update: 2024-09-21 19:37:24 UTC


README

带有示例和辅助工具的流程包,用于实现安全的表单上传

描述

当使用Flow Form Framework的默认FileUpload元素时,会在默认(persistent)资源集合中创建PersistentResource实例,为每个资源创建公开可访问的URL。此包配置所有FileUpload字段使用新的资源集合formUploads,该集合使用wwwision/privateresources包提供的“私有资源”。

这还包括一个表单结束器,用于在资源经过处理或通过电子邮件发送等操作后删除上传的资源。

安装

composer require wwwision/form-securefileupload

用法

通过安装此包,通过FileUpload表单元素上传的文件将自动存储在受保护的formUploads资源集合中。

清理上传的文件

使用此包,上传的文件不再通过有效的令牌从“外部”访问(见https://github.com/bwaidelich/Wwwision.PrivateResources)。然而,它们仍然在服务器文件系统中持久化(默认情况下),并通过neos_flow_resourcemanagement_persistentresource数据库表引用。

为了在处理上传文件后删除它们,可以使用提供的RemoveUploads结束器。

来自表单定义(yaml)

type: 'Neos.Form:Form'
identifier: 'contact'
label: 'Contact form'
renderables:
  -
    type: 'Neos.Form:Page'
    identifier: 'page-one'
    # renderables: ...
finishers:
  -
    # process uploads (e.g. send via email)
    identifier: 'Neos.Form:Email'
    options:
      attachAllPersistentResources: true
      # ...
  -
    # delete persistent resources
    identifier: 'Wwwision.Form.SecureFileUpload:RemoveUploadsFinisher'

注意:在当前实现中,RemoveUploads结束器遍历所有表单元素并删除所有PersistentResource实例。为了更细粒度的行为,您应该创建一个自定义结束器(或者向我发送一个pull request *g)

表单构建器

当然,此包可以与neos/form-builder包一起使用。为了能够从后端附加结束器,需要一个相应的节点类型和融合定义

NodeTypes.yaml

'Your.Package:RemoveUploadsFinisher':
  superTypes:
    'Neos.Form.Builder:AbstractFinisher': true
  ui:
    label: 'Remove Uploads Finisher'
    icon: 'icon-trash'

root.fusion:

prototype(Your.Package:RemoveUploadsFinisher.Definition) < prototype(Neos.Form.Builder:Finisher.Definition) {
    formElementType = 'Wwwision.Form.SecureFileUpload:Finisher.RemoveUploads'
}