ユースケース
オブジェクトストレージブループリントがサポートする一般的なシナリオを探ります:
File Hosting
総ストレージ使用量とアップロード量に基づいて顧客に請求します。
Backup Services
バックアップデータのアップロードを追跡し、保存されたGB単位で課金します。
Media CDN
メディアのアップロードを監視し、ストレージと帯域幅に応じて請求します。
Document Management
顧客ごとのドキュメントアップロードを追跡し、使用量ベースの課金を行います。
ストレージのアップロード、ファイルホスティング、CDN利用、バックアップサービスなどの課金に最適です。
クイックスタート
消費されたバイトでオブジェクトストレージのアップロードを追跡します:
Install the SDK
npm install @dodopayments/ingestion-blueprints
Get Your API Keys
- Dodo Payments API Key: Dodo Payments Dashboardから取得します
- Storage Provider API Key: AWS S3、Google Cloud Storage、Azureなどから取得します
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
});
import { Ingestion, trackObjectStorage } from '@dodopayments/ingestion-blueprints';
import { Storage } from '@google-cloud/storage';
import fs from 'fs';
const ingestion = new Ingestion({
apiKey: process.env.DODO_PAYMENTS_API_KEY,
environment: 'test_mode',
eventName: 'object_storage_upload'
});
const storage = new Storage();
const bucket = storage.bucket('my-bucket');
// Read the file
const fileBuffer = fs.readFileSync('./image.png');
// Upload to GCS
await bucket.file('uploads/image.png').save(fileBuffer);
// Track the upload
await trackObjectStorage(ingestion, {
customerId: 'customer_456',
bytes: fileBuffer.length,
metadata: {
bucket: 'my-bucket',
key: 'uploads/image.png'
}
});
取り込み設定
Dodo Paymentsダッシュボードから取得したAPIキー。
環境モード:test_mode または live_mode。
オブジェクトストレージの追跡オプション
アップロードされたバイト数。バイト単位の課金には必須です。
バケット名、コンテンツタイプなどのアップロードに関する任意のメタデータ。
ベストプラクティス
アップロード前後の追跡:エラーハンドリング戦略に応じて、実際のアップロードの前または後にイベントを追跡できます。
アップロードの失敗への対応:失敗した操作に対して課金されないように、成功したアップロードのみを追跡してください。