> ## 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.

# Object Storage Blueprint

> Track file uploads and storage usage for S3, Google Cloud Storage, Azure Blob, and other object storage services.

## Use Cases

Explore common scenarios supported by the Object Storage Blueprint:

<CardGroup cols={2}>
  <Card title="File Hosting" icon="folder">
    Bill customers based on total storage usage and upload volume.
  </Card>

  <Card title="Backup Services" icon="shield">
    Track backup data uploads and charge per GB stored.
  </Card>

  <Card title="Media CDN" icon="photo-film">
    Monitor media uploads and bill for storage and bandwidth.
  </Card>

  <Card title="Document Management" icon="file">
    Track document uploads per customer for usage-based pricing.
  </Card>
</CardGroup>

<Info>
  Perfect for billing based on storage uploads, file hosting, CDN usage, or backup services.
</Info>

## Quick Start

Track object storage uploads with bytes consumed:

<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**: Get it from [Dodo Payments Dashboard](https://app.dodopayments.com/developer/api-keys)
    * **Storage Provider API Key**: From AWS S3, Google Cloud Storage, Azure, etc.
  </Step>

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

    * **Event Name**: `object_storage_upload` (or your preferred name)
    * **Aggregation Type**: `sum` to track total bytes uploaded
    * **Over Property**: `bytes` to bill based on storage size
  </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>

## Configuration

### Ingestion Configuration

<ParamField path="apiKey" type="string" required>
  Your Dodo Payments API key from the dashboard.
</ParamField>

<ParamField path="environment" type="string" required>
  Environment mode: `test_mode` or `live_mode`.
</ParamField>

<ParamField path="eventName" type="string" required>
  Event name that matches your meter configuration.
</ParamField>

### Track Object Storage Options

<ParamField path="customerId" type="string" required>
  The customer ID for billing attribution.
</ParamField>

<ParamField path="bytes" type="number">
  Number of bytes uploaded. Required for byte-based billing.
</ParamField>

<ParamField path="metadata" type="object">
  Optional metadata about the upload like bucket name, content type, etc.
</ParamField>

## Best Practices

<Tip>
  **Track Before or After Upload**: You can track the event before or after the actual upload depending on your error handling strategy.
</Tip>

<Warning>
  **Handle Upload Failures**: Only track successful uploads to avoid billing for failed operations.
</Warning>
