跳转到主要内容

用例

探索对象存储蓝图支持的常见场景:

文件托管

根据总存储使用量和上传量向客户收费。

备份服务

跟踪备份数据上传并按存储的 GB 收费。

媒体 CDN

监控媒体上传并按存储和带宽收费。

文档管理

按客户跟踪文档上传以实现基于使用量的定价。
非常适合基于存储上传、文件托管、CDN 使用或备份服务进行计费。

快速开始

跟踪对象存储上传的字节消耗:
1

安装 SDK

npm install @dodopayments/ingestion-blueprints
2

获取您的 API 密钥

  • Dodo Payments API 密钥:从 Dodo Payments Dashboard 获取
  • 存储提供商 API 密钥:来自 AWS S3、Google Cloud Storage、Azure 等。
3

创建计量器

在您的 Dodo Payments Dashboard 中创建计量器:
  • 事件名称object_storage_upload(或您首选的名称)
  • 聚合类型sum 用于跟踪上传的总字节数
  • 超属性bytes 用于根据存储大小计费
4

跟踪存储使用情况

import { Ingestion, trackObjectStorage } from '@dodopayments/ingestion-blueprints';
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
import fs from 'fs';

const ingestion = new Ingestion({
  apiKey: process.env.DODO_PAYMENTS_API_KEY,
  environment: 'test_mode',
  eventName: 'object_storage_upload'
});

const s3 = new S3Client({ region: 'us-east-1' });

// Read the file (example: from disk or request)
const fileBuffer = fs.readFileSync('./document.pdf');

// Upload to S3
const command = new PutObjectCommand({
  Bucket: 'my-bucket',
  Key: 'uploads/document.pdf',
  Body: fileBuffer
});

await s3.send(command);

// Track the upload
await trackObjectStorage(ingestion, {
  customerId: 'customer_123',
  bytes: fileBuffer.length
});

配置

数据摄取配置

apiKey
string
required
您在仪表板上获取的 Dodo Payments API 密钥。
environment
string
required
环境模式:test_modelive_mode
eventName
string
required
与您的计量器配置匹配的事件名称。

跟踪对象存储选项

customerId
string
required
用于计费归属的客户 ID。
bytes
number
上传的字节数。基于字节计费时必需。
metadata
object
有关上传的可选元数据,如存储桶名称、内容类型等。

最佳实践

上传前或上传后跟踪:您可以根据错误处理策略在实际上传之前或之后跟踪事件。
处理上传失败:仅跟踪成功的上传,以避免对失败的操作进行计费。