Bỏ qua, đến nội dung

Cài đặt và sử dụng

Kích hoạt plugin

Vào Settings → Plugin Manager, bật @digiforce-nc/plugin-field-attachment-url. Plugin phụ thuộc plugin-file-manager — đảm bảo plugin này cũng đang hoạt động.

Yêu cầu trước khi dùng

  • Có ít nhất một storage được cấu hình dạng public trong plugin-file-manager (ví dụ: S3 bucket với public read, hoặc local storage với public URL).
  • Đã có collection quản lý file (attachments) sử dụng storage đó.

Thêm field Attachment URL

  1. Mở Collection Manager → chọn collection cần thêm field.
  2. Thêm field mới → chọn interface Attachment URL.
  3. Đặt tên field (ví dụ: contractFile).
  4. Lưu — field sẽ hiển thị component chọn file trên form.
typescript
const attachmentField = {
  name: 'contractFile',
  type: 'string',
  interface: 'attachmentURL',
  uiSchema: {
    type: 'string',
    title: 'File hợp đồng',
    'x-component': 'AttachmentUrl',
  },
};

Cấu hình public storage

Plugin tự động tìm các collection có public storage thông qua server action collections:listFileCollectionsWithPublicStorage. Để collection xuất hiện trong danh sách:

  1. Vào plugin-file-managerStorage Management.
  2. Tạo hoặc chỉnh sửa storage, đảm bảo bật tùy chọn public access.
  3. Gán storage cho collection quản lý file.

Cách sử dụng trên giao diện

  1. Mở form bản ghi chứa field Attachment URL.
  2. Click vào field → danh sách file collection khả dụng sẽ hiển thị.
  3. Chọn file từ collection → URL được tự động điền.
  4. Preview file (hình ảnh hiển thị thumbnail, file khác hiển thị icon loại file).
  5. Lưu bản ghi — URL được lưu dưới dạng chuỗi trong database.

Gọi API lấy danh sách file collections

typescript
const response = await api.resource('collections').listFileCollectionsWithPublicStorage();
const collections = response.data.data;

Response trả về danh sách collection kèm thông tin storage:

json
[
  {
    "name": "attachments",
    "storage": {
      "type": "s3",
      "baseUrl": "https://cdn.example.com"
    }
  }
]

Lưu ý

  • Giá trị field là URL string — nếu file bị xóa khỏi storage, URL sẽ trở thành dead link.
  • Chỉ hiển thị collection có public storage; collection với private storage không xuất hiện.
  • Plugin không upload file — chỉ tham chiếu file đã có trong hệ thống file manager.