You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apostrophe 3 CMS附件模块自定义文件组配置错误排查

Apostrophe 3 CMS 自定义文件组配置错误修复

问题背景

需要在Apostrophe 3 CMS的附件模块中新增仅支持PDF的pdf文件组和支持归档文件的zip文件组,参考Apostrophe 2的默认配置编写了自定义配置,但上传有效的ZIP文件时,出现错误提示:"File type was not accepted. Allowed extensions: "。

错误原因

配置文件存在嵌套层级错误。Apostrophe 3中配置@apostrophecms/attachment模块时,无需嵌套两层options及模块名称包裹,错误的层级导致自定义fileGroups未被系统正确加载,因此无法识别指定的文件组规则。

正确配置步骤

1. 修正附件模块配置文件

修改modules/@apostrophecms/attachment/index.js,直接在模块的options下定义fileGroups,保留默认的image和office组并新增自定义组:

// modules/@apostrophecms/attachment/index.js
module.exports = {
  options: {
    fileGroups: [
      // 自定义PDF文件组
      {
        name: 'pdf',
        label: 'PDF',
        extensions: ['pdf'],
        extensionMaps: {},
        image: false
      },
      // 自定义ZIP文件组
      {
        name: 'zip',
        label: 'ZIP',
        extensions: ['zip'],
        extensionMaps: {},
        image: false
      },
      // 保留默认图片组(可按需调整支持的扩展名)
      {
        name: 'image',
        label: 'Image',
        extensions: ['gif', 'jpg', 'png', 'svg', 'jpeg'],
        extensionMaps: {
          jpeg: 'jpg'
        },
        image: true
      },
      // 保留默认Office文件组
      {
        name: 'office',
        label: 'Office',
        extensions: ['txt', 'rtf', 'pdf', 'xls', 'ppt', 'doc', 'pptx', 'sldx', 'ppsx', 'potx', 'xlsx', 'xltx', 'csv', 'docx', 'dotx'],
        extensionMaps: {},
        image: false
      }
    ]
  }
};

2. 验证Widget字段配置

原有Widget中的字段配置无需修改,保持如下即可:

file: {
  label: 'File',
  type: 'attachment',
  fileGroup: 'zip'
}

完成上述修改后,重启Apostrophe 3项目,即可正常上传符合自定义文件组规则的文件。


内容的提问来源于stack exchange,提问作者Julian Vogels

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 17:57:27