> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# オブジェクトストレージブループリント

> S3、Google Cloud Storage、Azure Blob、その他のオブジェクトストレージサービスのファイルアップロードとストレージ使用量を追跡します。

## ユースケース

オブジェクトストレージブループリントがサポートする一般的なシナリオを探ります：

<CardGroup cols={2}>
  <Card title="File Hosting" icon="folder">
    総ストレージ使用量とアップロード量に基づいて顧客に請求します。
  </Card>

  <Card title="Backup Services" icon="shield">
    バックアップデータのアップロードを追跡し、保存されたGB単位で課金します。
  </Card>

  <Card title="Media CDN" icon="photo-film">
    メディアのアップロードを監視し、ストレージと帯域幅に応じて請求します。
  </Card>

  <Card title="Document Management" icon="file">
    顧客ごとのドキュメントアップロードを追跡し、使用量ベースの課金を行います。
  </Card>
</CardGroup>

<Info>
  ストレージのアップロード、ファイルホスティング、CDN利用、バックアップサービスなどの課金に最適です。
</Info>

## クイックスタート

消費されたバイトでオブジェクトストレージのアップロードを追跡します：

<Steps>
  <Step title="Install the SDK">
    ```bash theme={null}
    npm install @dodopayments/ingestion-blueprints
    ```
  </Step>

  <Step title="Get Your API Keys">
    * **Dodo Payments API Key**: [Dodo Payments Dashboard](https://app.dodopayments.com/developer/api-keys)から取得します
    * **Storage Provider API Key**: AWS S3、Google Cloud Storage、Azureなどから取得します
  </Step>

  <Step title="Create a Meter">
    [Buy the meter in your Dodo Payments Dashboard](https://app.dodopayments.com/):

    * **Event Name**: `object_storage_upload`（またはお好みの名前）
    * **Aggregation Type**: `sum` でアップロードされた総バイト数を追跡
    * **Over Property**: `bytes` でストレージサイズに基づいて請求
  </Step>

  <Step title="Track Storage Usage">
    <CodeGroup>
      ```javascript AWS S3 Upload theme={null}
      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
      });
      ```

      ```javascript Google Cloud Storage theme={null}
      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'
        }
      });
      ```
    </CodeGroup>
  </Step>
</Steps>

## 設定

### 取り込み設定

<ParamField path="apiKey" type="string" required>
  Dodo Paymentsダッシュボードから取得したAPIキー。
</ParamField>

<ParamField path="environment" type="string" required>
  環境モード：`test_mode` または `live_mode`。
</ParamField>

<ParamField path="eventName" type="string" required>
  メーター構成に一致するイベント名。
</ParamField>

### オブジェクトストレージの追跡オプション

<ParamField path="customerId" type="string" required>
  課金の帰属先となる顧客ID。
</ParamField>

<ParamField path="bytes" type="number">
  アップロードされたバイト数。バイト単位の課金には必須です。
</ParamField>

<ParamField path="metadata" type="object">
  バケット名、コンテンツタイプなどのアップロードに関する任意のメタデータ。
</ParamField>

## ベストプラクティス

<Tip>
  **アップロード前後の追跡**：エラーハンドリング戦略に応じて、実際のアップロードの前または後にイベントを追跡できます。
</Tip>

<Warning>
  **アップロードの失敗への対応**：失敗した操作に対して課金されないように、成功したアップロードのみを追跡してください。
</Warning>
