메인 콘텐츠로 건너뛰기

사용 사례

객체 저장소 청사진에서 지원하는 일반적인 시나리오를 탐색합니다:

파일 호스팅

총 저장 사용량 및 업로드 볼륨에 따라 고객에게 요금을 청구합니다.

백업 서비스

백업 데이터 업로드를 추적하고 저장된 GB당 요금을 청구합니다.

미디어 CDN

미디어 업로드를 모니터링하고 저장 및 대역폭에 대해 요금을 청구합니다.

문서 관리

사용 기반 가격 책정을 위해 고객별로 문서 업로드를 추적합니다.
저장 업로드, 파일 호스팅, CDN 사용 또는 백업 서비스에 따라 요금을 청구하는 데 적합합니다.

빠른 시작

소비된 바이트로 객체 저장소 업로드를 추적합니다:
1

SDK 설치

npm install @dodopayments/ingestion-blueprints
2

API 키 받기

  • Dodo Payments API 키: Dodo Payments 대시보드에서 받습니다.
  • 저장 제공업체 API 키: AWS S3, Google Cloud Storage, Azure 등에서 받습니다.
3

미터 생성

Dodo Payments 대시보드에서 미터를 생성합니다:
  • 이벤트 이름: 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_mode 또는 live_mode.
eventName
string
required
미터 구성과 일치하는 이벤트 이름입니다.

객체 저장소 추적 옵션

customerId
string
required
청구 귀속을 위한 고객 ID입니다.
bytes
number
업로드된 바이트 수입니다. 바이트 기반 청구에 필요합니다.
metadata
object
버킷 이름, 콘텐츠 유형 등 업로드에 대한 선택적 메타데이터입니다.

모범 사례

업로드 전 또는 후 추적: 오류 처리 전략에 따라 실제 업로드 전후에 이벤트를 추적할 수 있습니다.
업로드 실패 처리: 실패한 작업에 대해 요금을 청구하지 않도록 성공적인 업로드만 추적합니다.