Convenient static methods for loading assets from modules, URIs, or metadata. Provides batch loading capabilities with Promise-based API for efficient asset management.
A helper that wraps Asset.fromModule(module).downloadAsync for convenience, supporting batch loading.
/**
* A helper that wraps Asset.fromModule(module).downloadAsync for convenience.
* @param moduleId - An array of require('path/to/file') or external network URLs.
* Can also be just one module or URL without an Array.
* @returns Promise that fulfills with an array of Assets when the asset(s) has been saved to disk.
*/
static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]>;Usage Examples:
import { Asset } from "expo-asset";
// Load single asset
const [asset] = await Asset.loadAsync(require('./assets/icon.png'));
console.log("Loaded:", asset.localUri);
// Load multiple assets
const assets = await Asset.loadAsync([
require('./assets/icon.png'),
require('./assets/background.jpg'),
require('./assets/font.ttf')
]);
console.log("Loaded", assets.length, "assets");
assets.forEach(asset => {
console.log(`${asset.name}.${asset.type} -> ${asset.localUri}`);
});
// Load from URLs
const [webAsset] = await Asset.loadAsync([
'https://example.com/image.png'
]);
// Mixed loading
const mixedAssets = await Asset.loadAsync([
require('./assets/local.png'),
'https://example.com/remote.jpg'
]);Returns the Asset instance representing an asset given its module or URL.
/**
* Returns the Asset instance representing an asset given its module or URL.
* @param virtualAssetModule - The value of require('path/to/file') for the asset,
* external network URL, or asset object with uri/dimensions
* @returns The Asset instance for the asset.
*/
static fromModule(
virtualAssetModule: number | string | { uri: string; width: number; height: number }
): Asset;Usage Examples:
import { Asset } from "expo-asset";
// From require() module
const assetFromModule = Asset.fromModule(require('./assets/logo.png'));
console.log("Asset name:", assetFromModule.name);
// From URL string
const assetFromURL = Asset.fromModule('https://example.com/image.png');
console.log("Asset URI:", assetFromURL.uri);
// From asset object
const assetFromObject = Asset.fromModule({
uri: 'https://example.com/custom.png',
width: 200,
height: 150
});
console.log("Asset dimensions:", assetFromObject.width, 'x', assetFromObject.height);
// Then download if needed
if (!assetFromModule.downloaded) {
await assetFromModule.downloadAsync();
}Creates Asset instance from URI string.
/**
* Create Asset instance from URI string.
* @param uri - Asset URI
* @returns Asset instance
*/
static fromURI(uri: string): Asset;Usage Examples:
import { Asset } from "expo-asset";
// Create from web URL
const webAsset = Asset.fromURI('https://example.com/image.png');
console.log("Asset type:", webAsset.type); // "png"
// Create from Base64 data URI
const base64Asset = Asset.fromURI('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==');
console.log("Asset type:", base64Asset.type); // "png"
// Create from local file URI
const localAsset = Asset.fromURI('file:///path/to/local/image.jpg');
console.log("Asset type:", localAsset.type); // "jpg"Creates Asset instance from metadata. This method is primarily used internally by the Expo asset system and React Native's asset registry.
/**
* Create Asset instance from metadata. This method is primarily used internally
* by the Expo asset system and React Native's asset registry.
* @param meta - Asset metadata from the bundler
* @returns Asset instance
* @internal
*/
static fromMetadata(meta: AssetMetadata): Asset;This method creates Asset instances from the metadata provided by the bundler during the build process. It's not typically used directly in application code, but rather called internally when assets are resolved from require() statements.
/**
* Asset metadata interface containing bundler-provided information about assets.
* This is primarily used internally by the asset system.
*/
interface AssetMetadata {
/** The HTTP server location where the asset is served from during development */
httpServerLocation: string;
/** The name of the asset file without extension */
name: string;
/** The MD5 hash of the asset's data */
hash: string;
/** The file extension/type of the asset */
type: string;
/** Array of available scale factors (e.g., [1, 2, 3] for @1x, @2x, @3x) */
scales: number[];
/** The width of the asset in pixels (for images) */
width?: number;
/** The height of the asset in pixels (for images) */
height?: number;
/** Direct URI to the asset (optional) */
uri?: string;
/** Array of file hashes for each scale variant */
fileHashes?: string[];
/** Array of file URIs for each scale variant */
fileUris?: string[];
}