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

# Kế Hoạch Lưu Trữ Đối Tượng

> Theo dõi việc tải lên tệp và mức sử dụng lưu trữ cho S3, Google Cloud Storage, Azure Blob và các dịch vụ lưu trữ đối tượng khác.

## Các Trường Hợp Sử Dụng

Khám phá các kịch bản phổ biến được hỗ trợ bởi Kế Hoạch Lưu Trữ Đối Tượng:

<CardGroup cols={2}>
  <Card title="File Hosting" icon="folder">
    Hóa đơn khách hàng dựa trên tổng mức sử dụng lưu trữ và dung lượng tải lên.
  </Card>

  <Card title="Backup Services" icon="shield">
    Theo dõi việc tải lên dữ liệu sao lưu và tính phí theo GB được lưu trữ.
  </Card>

  <Card title="Media CDN" icon="photo-film">
    Giám sát việc tải phương tiện và tính phí cho lưu trữ và băng thông.
  </Card>

  <Card title="Document Management" icon="file">
    Theo dõi việc tải tài liệu theo từng khách hàng để định giá dựa trên mức sử dụng.
  </Card>
</CardGroup>

<Info>
  Hoàn hảo cho việc tính phí dựa trên tải lên lưu trữ, lưu trữ tệp, sử dụng CDN hoặc dịch vụ sao lưu.
</Info>

## Bắt Đầu Nhanh

Theo dõi việc tải lên lưu trữ đối tượng với số byte đã tiêu thụ:

<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**: Lấy nó từ [Dodo Payments Dashboard](https://app.dodopayments.com/developer/api-keys)
    * **Storage Provider API Key**: Từ AWS S3, Google Cloud Storage, Azure, v.v.
  </Step>

  <Step title="Create a Meter">
    Tạo một meter trong [Dodo Payments Dashboard](https://app.dodopayments.com/):

    * **Event Name**: `object_storage_upload` (hoặc tên tùy chọn của bạn)
    * **Aggregation Type**: `sum` để theo dõi tổng số byte đã tải lên
    * **Over Property**: `bytes` để tính phí dựa trên kích thước lưu trữ
  </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>

## Cấu Hình

### Cấu Hình Nhập Dữ Liệu

<ParamField path="apiKey" type="string" required>
  Khóa API Dodo Payments của bạn từ bảng điều khiển.
</ParamField>

<ParamField path="environment" type="string" required>
  Chế độ môi trường: `test_mode` hoặc `live_mode`.
</ParamField>

<ParamField path="eventName" type="string" required>
  Tên sự kiện khớp với cấu hình meter của bạn.
</ParamField>

### Theo Dõi Tùy Chọn Lưu Trữ Đối Tượng

<ParamField path="customerId" type="string" required>
  Mã định danh khách hàng cho việc phân bổ hóa đơn.
</ParamField>

<ParamField path="bytes" type="number">
  Số byte đã tải lên. Cần thiết cho việc tính phí theo byte.
</ParamField>

<ParamField path="metadata" type="object">
  Siêu dữ liệu tùy chọn về lần tải lên như tên bucket, loại nội dung, v.v.
</ParamField>

## Thực Hành Tốt Nhất

<Tip>
  **Track Before or After Upload**: Bạn có thể theo dõi sự kiện trước hoặc sau khi tải lên tùy thuộc vào chiến lược xử lý lỗi của bạn.
</Tip>

<Warning>
  **Handle Upload Failures**: Chỉ theo dõi các lần tải lên thành công để tránh tính phí cho các thao tác không thành công.
</Warning>
