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

# Plano de Almacenamiento de Objetos

> Realiza un seguimiento de las cargas de archivos y el uso de almacenamiento para S3, Google Cloud Storage, Azure Blob y otros servicios de almacenamiento de objetos.

## Casos de Uso

Explora escenarios comunes soportados por el Plano de Almacenamiento de Objetos:

<CardGroup cols={2}>
  <Card title="File Hosting" icon="folder">
    Factura a los clientes según el uso total de almacenamiento y el volumen de cargas.
  </Card>

  <Card title="Backup Services" icon="shield">
    Realiza un seguimiento de las cargas de datos de respaldo y cobra por GB almacenado.
  </Card>

  <Card title="Media CDN" icon="photo-film">
    Supervisa las cargas de medios y factura por almacenamiento y ancho de banda.
  </Card>

  <Card title="Document Management" icon="file">
    Realiza un seguimiento de las cargas de documentos por cliente para precios basados en el uso.
  </Card>
</CardGroup>

<Info>
  Perfecto para facturación basada en cargas de almacenamiento, alojamiento de archivos, uso de CDN o servicios de respaldo.
</Info>

## Inicio Rápido

Realiza un seguimiento de las cargas de almacenamiento de objetos con bytes consumidos:

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

  <Step title="Create a Meter">
    Crea un medidor en tu [Dodo Payments Dashboard](https://app.dodopayments.com/):

    * **Event Name**: `object_storage_upload` (o el nombre que prefieras)
    * **Aggregation Type**: `sum` para rastrear el total de bytes cargados
    * **Over Property**: `bytes` para facturar según el tamaño de almacenamiento
  </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>

## Configuración

### Configuración de Ingesta

<ParamField path="apiKey" type="string" required>
  Tu clave de API de Dodo Payments desde el panel.
</ParamField>

<ParamField path="environment" type="string" required>
  Modo de entorno: `test_mode` o `live_mode`.
</ParamField>

<ParamField path="eventName" type="string" required>
  Nombre del evento que coincida con la configuración de tu medidor.
</ParamField>

### Opciones de Seguimiento de Almacenamiento de Objetos

<ParamField path="customerId" type="string" required>
  El ID del cliente para la atribución de facturación.
</ParamField>

<ParamField path="bytes" type="number">
  Número de bytes cargados. Requerido para facturación basada en bytes.
</ParamField>

<ParamField path="metadata" type="object">
  Metadatos opcionales sobre la carga, como el nombre del bucket, tipo de contenido, etc.
</ParamField>

## Mejores Prácticas

<Tip>
  **Rastrea antes o después de la carga**: Puedes registrar el evento antes o después de la carga real según tu estrategia de manejo de errores.
</Tip>

<Warning>
  **Gestiona fallos en la carga**: Solo registra las cargas exitosas para evitar facturar operaciones fallidas.
</Warning>
