RTSDK
    Preparing search index...

    Class AssetFactory

    Factory for creating Asset instances. Use this factory to create or upload assets in the Topia platform.

    This factory should be instantiated once per application and reused across your codebase.

    asset, factory, create, upload, instantiate, topia

    // In your initialization file (e.g., utils/topiaInit.ts)
    import { Topia, AssetFactory } from "@rtsdk/topia";
    const topia = new Topia({ config });
    export const Asset = new AssetFactory(topia);

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    credentials: undefined | InteractiveCredentials
    jwt?: string
    requestOptions: object
    topia: Topia

    Methods

    • Instantiate a new instance of Asset class with the specified asset ID.

      Parameters

      Returns Asset

      Returns a new Asset object with the asset id.

      This method creates a new Asset controller instance that can be used to interact with an existing asset. It does not create a new asset in the database.

      create, instantiate, asset, initialize, get, instance

      // Import the pre-initialized factory from your app's initialization file
      import { Asset } from "utils/topiaInit.ts";

      // Create an Asset instance with credentials
      const assetInstance = await Asset.create(assetId, {
      credentials: {
      interactiveNonce,
      interactivePublicKey,
      assetId,
      urlSlug,
      visitorId
      }
      });

      // Use the instance to interact with the asset
      await assetInstance.fetchAssetById();
    • Parameters

      • __namedParameters: { error?: unknown; message?: string; params?: object; sdkMethod?: string }

      Returns {
          data: {};
          message: string;
          method: string;
          params: object;
          sdkMethod: undefined | string;
          stack: string;
          stackTrace: Error;
          status: number;
          success: boolean;
          url: string;
      }

    • Returns AxiosInstance

    • Upload a new Asset to the Topia platform and return a new instance of Asset class.

      Parameters

      Returns Promise<Asset>

      Returns a new Asset object with the asset details.

      This method both creates a new asset in the database and returns an Asset controller instance. A valid API key with appropriate permissions is required.

      upload, create, new, asset, add, store

      // Import the pre-initialized factory from your app's initialization file
      import { Asset } from "utils/topiaInit.ts";

      // Prepare the asset payload
      const assetPayload = {
      assetName: "My Decorative Asset",
      bottomLayerURL: "https://example.com/bottom-layer.png",
      creatorTags: { "decorations": true },
      tagJson: "[{"label":"decorations","value":"decorations"}]",
      isPublic: true,
      topLayerURL: "https://example.com/top-layer.png"
      };

      // Upload the asset using your API key
      const asset = await Asset.upload(assetPayload, apiKey);

      // Access the new asset's properties
      console.log(asset.id);