---
title: "文件管理 | Tajo"
description: "在 Brevo CRM 中上传和管理文件附件，为 Tajo 交易归档提供支撑"
url: https://tajo.io/zh-cn/docs/sales-crm/files/
markdown: https://tajo.io/zh-cn/docs/sales-crm/files.md
lang: zh-CN
author: "Set Noa"
author_url: https://tajo.io/zh-cn/set-noa/
robots: noindex
---

申请抢先体验

请输入您的名字和公司电子邮箱地址。我们会发送确认 Tajo 访问申请的链接。

# 文件管理

[Set Noa](https://tajo.io/zh-cn/set-noa/)

Brevo CRM Files API 让你可以上传和管理与 Tajo 平台中联系人、公司和交易相关联的文件附件。

## 概览

文件管理在以下场景中不可或缺：

- **交易归档** 保存方案、合同和协议
- **客户档案** 附加发票、收据和往来函件
- **忠诚度计划材料** 分享计划细则和权益说明
- **合规** 为企业账户保留文档审计记录
- **团队协作** 在销售团队成员之间共享资料

## 快速开始

### 上传文件

```http
POST https://api.brevo.com/v3/crm/files
Content-Type: multipart/form-data
api-key: YOUR_API_KEY

--boundary
Content-Disposition: form-data; name="file"; filename="enterprise-proposal.pdf"
Content-Type: application/pdf

[file content]
--boundary
Content-Disposition: form-data; name="dealIds"

deal_abc123def456
--boundary
Content-Disposition: form-data; name="companyIds"

comp_123456789
--boundary
Content-Disposition: form-data; name="contactIds"

12345
--boundary--
```

### 响应

```json
{
  "id": "file_001",
  "name": "enterprise-proposal.pdf",
  "size": 245760,
  "contentType": "application/pdf",
  "dealIds": ["deal_abc123def456"],
  "companyIds": ["comp_123456789"],
  "contactIds": [12345],
  "created_at": "2026-01-25T14:30:00Z"
}
```

## 获取文件

### 列出全部文件

```http
GET https://api.brevo.com/v3/crm/files?limit=50&offset=0&sort=desc
Content-Type: application/json
api-key: YOUR_API_KEY
```

### 响应

```json
{
  "items": [
    {
      "id": "file_001",
      "name": "enterprise-proposal.pdf",
      "size": 245760,
      "contentType": "application/pdf",
      "dealIds": ["deal_abc123def456"],
      "companyIds": ["comp_123456789"],
      "created_at": "2026-01-25T14:30:00Z"
    }
  ],
  "total": 1
}
```

### 筛选文件

```http
GET https://api.brevo.com/v3/crm/files?filters[dealIds]=deal_abc123def456&sort=created_at:desc
```

### 获取单个文件

```http
GET https://api.brevo.com/v3/crm/files/{file_id}
Content-Type: application/json
api-key: YOUR_API_KEY
```

### 下载文件

```http
GET https://api.brevo.com/v3/crm/files/{file_id}/data
api-key: YOUR_API_KEY
```

## 文件管理自动化

### 交易文档工作流

在整个交易生命周期内自动管理文档：

```javascript
class DealDocumentManager {
  constructor() {
    this.filesApi = new FilesApi();
  }

  async attachProposal(dealId, proposalBuffer, companyName) {
    const fileName = `proposal-${companyName.toLowerCase().replace(/\s+/g, '-')}-${Date.now()}.pdf`;

    const file = await this.filesApi.uploadFile({
      file: proposalBuffer,
      fileName: fileName,
      dealIds: [dealId]
    });

    // Create a note referencing the uploaded proposal
    await this.notesApi.createNote({
      text: `Proposal uploaded: ${fileName}`,
      dealIds: [dealId]
    });

    return file;
  }

  async attachContract(dealId, contractBuffer, companyId) {
    const fileName = `contract-${dealId}-${new Date().toISOString().slice(0, 10)}.pdf`;

    const file = await this.filesApi.uploadFile({
      file: contractBuffer,
      fileName: fileName,
      dealIds: [dealId],
      companyIds: [companyId]
    });

    return file;
  }

  async getDealDocuments(dealId) {
    const files = await this.filesApi.getFiles({
      filters: { dealIds: dealId },
      sort: 'created_at:desc'
    });

    return {
      proposals: files.items.filter(f => f.name.startsWith('proposal-')),
      contracts: files.items.filter(f => f.name.startsWith('contract-')),
      other: files.items.filter(f =>
        !f.name.startsWith('proposal-') && !f.name.startsWith('contract-')
      ),
      totalSize: files.items.reduce((sum, f) => sum + f.size, 0)
    };
  }
}
```

### 忠诚度计划文档

```javascript
class LoyaltyDocumentManager {
  async generateAndAttachBenefitsSummary(companyId, tier) {
    const company = await this.companiesApi.getCompany(companyId);

    const summary = await this.generateBenefitsPDF({
      companyName: company.name,
      tier: tier,
      benefits: this.getTierBenefits(tier),
      annualSpend: company.attributes.annual_spend,
      pointsBalance: company.attributes.loyalty_points
    });

    return await this.filesApi.uploadFile({
      file: summary,
      fileName: `loyalty-benefits-${tier.toLowerCase().replace(/\s+/g, '-')}.pdf`,
      companyIds: [companyId]
    });
  }

  async attachTierUpgradeDocuments(companyId, oldTier, newTier) {
    const documents = [
      { name: 'tier-upgrade-confirmation', content: this.generateUpgradeConfirmation(oldTier, newTier) },
      { name: 'new-benefits-guide', content: this.generateBenefitsGuide(newTier) }
    ];

    const uploaded = [];
    for (const doc of documents) {
      const file = await this.filesApi.uploadFile({
        file: doc.content,
        fileName: `${doc.name}-${Date.now()}.pdf`,
        companyIds: [companyId]
      });
      uploaded.push(file);
    }

    return uploaded;
  }
}
```

## 支持的文件类型

| 类别 | 扩展名 | 最大体积 |
| --- | --- | --- |
| 文档 | `.pdf`、`.doc`、`.docx`、`.txt` | 10 MB |
| 表格 | `.xls`、`.xlsx`、`.csv` | 10 MB |
| 图片 | `.png`、`.jpg`、`.jpeg`、`.gif` | 5 MB |
| 演示文稿 | `.ppt`、`.pptx` | 10 MB |

## API 方法参考

```javascript
// Upload a file
const file = await filesApi.uploadFile({
  file: fileBuffer,
  fileName: 'proposal.pdf',
  dealIds: ['deal_abc123'],
  companyIds: ['comp_123']
});

// Get file metadata
const file = await filesApi.getFile('file_001');

// Download file data
const fileData = await filesApi.downloadFile('file_001');

// Delete file
await filesApi.deleteFile('file_001');

// List files with filtering
const files = await filesApi.getFiles({
  filters: { dealIds: 'deal_abc123' },
  sort: 'created_at:desc',
  limit: 50
});
```

## 最佳实践

1. **命名规范**：用带日期的描述性文件名，便于识别
2. **关联记录**：把文件关联到所有相关的交易、公司和联系人
3. **版本管理**：在文件名中加入版本号或日期
4. **体积控制**：上传前先压缩大文件
5. **访问控制**：定期检查文件关联关系，确保权限正确
6. **定期清理**：删除过期文档，保持 CRM 记录整洁

## 错误处理

```javascript
try {
  const file = await filesApi.uploadFile(fileData);
  console.log('File uploaded:', file.id);
} catch (error) {
  if (error.status === 400) {
    console.error('Invalid file data:', error.message);
  } else if (error.status === 413) {
    console.error('File size exceeds maximum limit');
  } else if (error.status === 415) {
    console.error('Unsupported file type');
  } else {
    console.error('Unexpected error:', error);
  }
}
```

## 下一步

- **[公司管理](https://tajo.io/zh-cn/docs/sales-crm/companies)**：管理企业客户
- **[交易管理](https://tajo.io/zh-cn/docs/sales-crm/deals)**：跟踪销售管道
- **[任务管理](https://tajo.io/zh-cn/docs/sales-crm/tasks)**：管理销售活动
- **[备注](https://tajo.io/zh-cn/docs/sales-crm/notes)**：记录客户互动
