or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

asset-management.mdindex.mdreact-hooks.mdstatic-loading.md
tile.json

asset-management.mddocs/

Asset Management

Core asset representation and management functionality. The Asset class provides complete metadata about assets and handles downloading to local cache with intelligent caching and platform-specific optimizations.

Capabilities

Asset Class

The main class representing an asset in your app with metadata and download capabilities.

/**
 * The Asset class represents an asset in your app. It gives metadata about the asset
 * (such as its name and type) and provides facilities to load the asset data.
 */
class Asset {
  /**
   * The name of the asset file without the extension. Also without the part from `@` onward
   * in the filename (used to specify scale factor for images).
   */
  name: string;

  /**
   * The extension of the asset filename.
   */
  readonly type: string;

  /**
   * The MD5 hash of the asset's data.
   */
  readonly hash: string | null;

  /**
   * A URI that points to the asset's data on the remote server. When running the published
   * version of your app, this refers to the location on Expo's asset server. When running
   * the app from Expo CLI during development, this URI points to Expo CLI's server.
   */
  readonly uri: string;

  /**
   * If the asset has been downloaded (by calling downloadAsync()), the file:// URI pointing
   * to the local file on the device that contains the asset data.
   */
  localUri: string | null;

  /**
   * If the asset is an image, the width of the image data divided by the scale factor.
   * The scale factor is the number after `@` in the filename, or `1` if not present.
   */
  width: number | null;

  /**
   * If the asset is an image, the height of the image data divided by the scale factor.
   * The scale factor is the number after `@` in the filename, or `1` if not present.
   */
  height: number | null;

  /**
   * Whether the asset has finished downloading from a call to downloadAsync().
   */
  downloaded: boolean;

  /**
   * Create new Asset instance
   * @param descriptor - Asset descriptor with metadata
   */
  constructor(descriptor: AssetDescriptor);
}

interface AssetDescriptor {
  name: string;
  type: string;
  hash?: string | null;
  uri: string;
  width?: number | null;
  height?: number | null;
}

Usage Examples:

import { Asset } from "expo-asset";

// Create asset from descriptor
const asset = new Asset({
  name: "icon",
  type: "png",
  hash: "abc123",
  uri: "https://example.com/icon.png",
  width: 100,
  height: 100
});

// Check if asset is downloaded
if (!asset.downloaded) {
  console.log("Asset not yet downloaded");
}

// Access asset properties
console.log("Asset name:", asset.name);
console.log("Asset type:", asset.type);
console.log("Remote URI:", asset.uri);
console.log("Local URI:", asset.localUri); // null until downloaded

Download Assets

Downloads the asset data to a local file in the device's cache directory.

/**
 * Downloads the asset data to a local file in the device's cache directory. Once the returned
 * promise is fulfilled without error, the localUri field of this asset points to a local file
 * containing the asset data. The asset is only downloaded if an up-to-date local file for the
 * asset isn't already present due to an earlier download.
 *
 * Note: There is no guarantee that files downloaded via downloadAsync persist between app sessions.
 * downloadAsync stores files in the caches directory, so it's up to the OS to clear this folder.
 * Downloaded assets are stored as ExponentAsset-{cacheFileId}.{extension} within the cache directory.
 *
 * @returns Promise which fulfills with the Asset instance
 */
downloadAsync(): Promise<this>;

Usage Examples:

import { Asset } from "expo-asset";

// Download single asset
const asset = Asset.fromModule(require('./assets/image.png'));
await asset.downloadAsync();

console.log("Downloaded to:", asset.localUri);
console.log("Is downloaded:", asset.downloaded); // true

// Chain multiple operations
const processedAsset = await Asset.fromModule(require('./assets/data.json'))
  .downloadAsync()
  .then(asset => {
    // Asset is now available locally
    return asset;
  });

// Handle download errors
try {
  await asset.downloadAsync();
} catch (error) {
  console.error("Download failed:", error.message);
}