Skip to content
bitzorcas
EN

Reference

文件模块

文件管理模块 — FileAssetService 用于上传/下载/删除,支持租户隔离、LocalFileStorage 集成和跨模块附件支持。

Last updated

Files 模块提供租户范围的文件资产管理,支持上传、下载、软删除和分页。文件与 Tickets 和 Chat 模块作为附件提供者集成。

端点

端点方法描述
/api/filesPOST上传文件(multipart 表单)
/api/files/{id}GET按 asset ID 下载文件
/api/files/{id}DELETE软删除文件
/api/filesGET分页文件列表

FileAsset 实体

public class FileAssetEntity : TenantSoftDeleteEntityBase
{
public string FileName { get; set; }
public string ContentType { get; set; }
public long FileSizeBytes { get; set; }
public string StoragePath { get; set; }
public string? Description { get; set; }
}

架构

FileEndpoints (Minimal API)
FileAssetService
├── IFileAssetRepository → SqlSugarFileAssetRepository
├── IFileStorage → LocalFileStorage
└── IFileEventPublisher → CapFileEventPublisher

上传流程

  1. 客户端发送 POST /api/files,附带 multipart 表单数据
  2. FileAssetService 通过 IFileStorage.SaveAsync() 读取流
  3. 元数据通过 SqlSugar 持久化到 FileAssetEntity
  4. IFileEventPublisher 发布 file.uploaded 集成事件
  5. 返回文件资源 ID 和元数据

跨模块附件

文件作为其他模块的附件骨干:

模块附件服务用途
TicketsFileAssetTicketAttachmentAccessService将文件附加到工单
ChatFileAssetChatAttachmentAccessService将文件附加到聊天消息

两者都实现特定模块的访问模式:

public interface ITicketAttachmentAccessService
{
Task<FileAssetEntity?> GetAttachmentAsync(Guid attachmentId, CancellationToken ct);
}
public interface IChatAttachmentAccessService
{
Task<FileAssetEntity?> GetAttachmentAsync(Guid attachmentId, CancellationToken ct);
}

存储配置

{
"Storage": {
"BasePath": "./storage/files"
}
}

文件存储在 {basePath}/{year}/{month}/{guid}.{extension}

另见