跳转到主要内容

用例

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

File Hosting

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

Backup Services

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

Media CDN

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

Document Management

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

快速开始

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

Install the SDK

npm install @dodopayments/ingestion-blueprints
2

Get Your API Keys

  • Dodo Payments API Key:从 Dodo Payments Dashboard 获取
  • Storage Provider API Key:来自 AWS S3、Google Cloud Storage、Azure 等
3

Create a Meter

在您的 Dodo Payments Dashboard 中创建计量器:
  • Event Nameobject_storage_upload(或您首选的名称)
  • Aggregation Typesum,以跟踪总上传字节数
  • Over Propertybytes,用于基于存储大小计费
4

Track Storage Usage

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
必填
来自控制面板的 Dodo Payments API 密钥。
environment
string
必填
环境模式:test_modelive_mode
eventName
string
必填
与您的计量器配置匹配的事件名称。

跟踪对象存储选项

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

最佳实践

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