nocobase-app-plugin-file
它能做什么
这项技能为 NocoBase 3 应用添加文件集合、上传、下载和预览功能。适合需要在业务记录上添加附件的开发者。
适用场景
- ✓当你希望用户在 NocoBase 应用的业务记录上添加文件时。
- ✓当你需要在应用中预览 Word、Excel 或 PowerPoint 文件时。
- ✓当你需要把 UI 库中的文件组件添加到页面上时。
技能链接
https://github.com/nocobase/nocobase/blob/v3-develop/packages/plugins/app-plugin-file/skills/nocobase-app-plugin-file/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我让用户为每个订单添加文件,并能在 NocoBase 应用中预览 Word 或 Excel 附件。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会使用文件插件提供的服务和路由辅助工具,然后添加应用所需的集合、页面和权限。在可用的地方,它会复用内置的文件预览组件。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Add files to an App
Use @nocobase/app-plugin-file/server and @nocobase/app-plugin-file/client. The plugin provides Repository managers, service tokens, and route helpers. The UI Library provides @nocobase/file-component-ui. The App or business plugin owns collections, migrations, Drive configuration, resource routes, permissions, and pages.
Inspect the App's existing registrations, migrations, disks, and resources first. Register the Server default export and the Client default factory before consumers, using the App's plugin lifecycle commands. The core does not create collections or routes.
Find and reuse the preview UI first
Inspect client/extensions/nocobase-file-component-ui/ before writing upload or preview components. Current Default templates preinstall this application-owned UI Library source and its client dependencies; older applications and other templates may not. Import from its index.ts, not from plugin-internal paths. Registering the plugin supplies services and translations; it does not automatically install or upgrade the copied UI.
| Format | UI Library preview | Content access |
|---|---|---|
| DOCX / XLSX / PPTX | Local @silurus/ooxml viewer |
Same-origin session credentials; no public URL or third-party service required |
| Raster image / PDF / text / Markdown / audio / video | Built-in preview components | See the content access rules below |
| Legacy DOC / XLS / PPT and OpenDocument | Office Online fallback | Internet-accessible absolute URL; cannot use the App session |
| Unsupported or unsafe active content | Explanation and optional download | Download still requires permission |
To show a record's files as thumbnails and chips, or take uploads beside a form or a comment, install the UI Library's attachment-list component (yes n | pnpm exec shadcn add @nocobase/attachment-list; its example is @nocobase/attachment-list-demo), map file records to AttachmentFile, and open FilePreviewDialog from its onPreview. For custom attachment lists, uploads or business associations, reuse FilePreviewDialog with file records and contentUrl; it requires no repository prop. Extend the existing UI or add the necessary content adapter rather than reimplementing format detection and dropping supported formats. A DOCX download fallback indicates a request/rendering failure or an outdated/custom component, not that the plugin lacks DOCX support. Report the actual failure and preserve its evidence.
If the installed package, synchronized Skill and copied UI disagree, inspect the resolved plugin version, run pnpm nocobase skills sync to refresh guidance, and reconcile the UI source separately. Skills synchronization does not upgrade UI Library copies.
Work incrementally
- Use standard File Repository routes, the Client File Repository and UI Library components for new attachment features. Save associations through the existing business API, whether standard CRUD or custom routes; do not migrate working business routes just to add files.
- Extend existing services, middleware, response adapters or installed UI components where needed. A necessary compatibility handler should delegate to File Repository; do not rebuild upload, storage and metadata handling with Drive or replace the whole CRUD stack.
- Inspect the App's registration, collection, disk and business save path together. Reuse what works; do not ask the user to choose an implementation or repeatedly explore source when the documented contract suffices.
- Verify one small upload → metadata query → content download before building UI. Then wire the returned IDs into the existing save/detail flow. Retain uploaded IDs if the business save fails, and run the affected checks after edits stabilize.
The following business example uses collection invoice_files, resource invoiceAttachments, connection main, and disk local. Adapt these to the App.
Collection
Create an App-owned, self-contained migration under database/main/migrations/ with
常见问题
插件会自动创建文件数据表吗?
不会。应用或业务插件负责管理集合、迁移和路由。
文件存放在哪里?
存放在应用配置的存储磁盘中。
涵盖哪些预览格式?
技能涵盖 Word、Excel 和 PowerPoint 的预览。
详情
作者的原始描述
Add file collections, uploads, downloads, DOCX/XLSX/PPTX previews, business attachments, and editable UI Library file components to a NocoBase 3 App using the public File Repository services.
repo: nocobase/nocobase
热度
- GitHub 星标
- 25k
- 排名
- #10097
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
nocobase-app-development
25k帮你的智能体为完整的 NocoBase 3 业务应用构建页面、路由、数据、权限和测试。
shadcn
25k帮你的智能体在 Web 项目中查找、添加、修复和美化 shadcn/ui 组件,并使用其官方文档和注册表。
nocobase-app-plugin-development
25k帮你的智能体在现有应用中创建和维护 NocoBase 3 插件,包括服务端、客户端、数据库和注册部分。
nocobase-app-upgrade
25k帮你的智能体把 NocoBase 应用升级到较新的模板版本,引入模板的更改,同时保留你自己的工作。