Vana SDK - v0.1.0
    Preparing search index...

    Class StorageManager

    Manages multiple storage providers with a unified interface for file operations.

    The StorageManager provides a consistent API for uploading, downloading, and managing files across different storage backends including IPFS, Pinata, Google Drive, and server-managed storage. It handles provider registration, default provider selection, and automatic fallback scenarios for robust file operations.

    Used internally by DataController for encrypted file storage, but can also be used directly for custom storage workflows. Each provider implements the StorageProvider interface to ensure consistent behavior across different storage backends.

    The manager supports provider-specific configurations and features while maintaining a uniform API surface for applications.

    import { StorageManager, IPFSStorage, PinataStorage } from '@opendatalabs/vana-sdk';

    const storage = new StorageManager();

    // Register multiple providers
    storage.register('ipfs', new IPFSStorage({
    apiEndpoint: 'https://api.pinata.cloud/pinning/pinFileToIPFS'
    }), true);
    storage.register('pinata', new PinataStorage({
    jwt: 'your-pinata-jwt-token'
    }));

    // Upload to default provider
    const result = await storage.upload(fileBlob, 'myfile.json');

    // Upload to specific provider
    const result2 = await storage.upload(fileBlob, 'myfile.json', 'pinata');

    [URL_PLACEHOLDER] | Storage Providers Guide for configuration details

    Index

    Methods

    • Registers a storage provider with the manager.

      Parameters

      • name: string

        Unique identifier for the provider

      • provider: StorageProvider

        The storage provider instance implementing the StorageProvider interface

      • isDefault: boolean = false

        Whether this provider should be set as the default (defaults to false)

      Returns void

      This method adds a new storage provider to the manager's registry and optionally sets it as the default provider for subsequent operations. If no default provider is currently set, the first registered provider automatically becomes the default.

      const pinata = new PinataStorage({ jwt: 'your-jwt-token' });
      storage.register('pinata', pinata, true); // Set as default

      const ipfs = new IPFSStorage({ apiEndpoint: 'https://...' });
      storage.register('ipfs', ipfs); // Not default
    • Uploads a file using the specified or default storage provider.

      Parameters

      • file: Blob

        The file blob to upload

      • Optionalfilename: string

        Optional custom filename (defaults to auto-generated name)

      • OptionalproviderName: string

        Optional provider identifier (uses default if not specified)

      Returns Promise<StorageUploadResult>

      A Promise that resolves to the storage upload result with URL and metadata

      This method uploads a file to the specified provider or falls back to the default provider if none is specified. The upload result includes the storage URL, file size, content type, and provider-specific metadata that can be used for subsequent operations.

      When no provider is available or upload fails

      // Upload to default provider
      const result = await storage.upload(fileBlob, 'data.json');
      console.log(`Uploaded to: ${result.url}`);

      // Upload to specific provider
      const result2 = await storage.upload(fileBlob, 'data.json', 'pinata');
    • Download a file using the specified or default provider

      Parameters

      • url: string

        The storage URL

      • OptionalproviderName: string

        Optional provider to use

      Returns Promise<Blob>

      Promise with file blob

    • List files using the specified or default provider

      Parameters

      • Optionaloptions: StorageListOptions

        Optional filtering and pagination

      • OptionalproviderName: string

        Optional provider to use

      Returns Promise<StorageFile[]>

      Promise with file list

    • Delete a file using the specified or default provider

      Parameters

      • url: string

        The storage URL

      • OptionalproviderName: string

        Optional provider to use

      Returns Promise<boolean>

      Promise with success status