Skip to main content

AssetClient

Client for converting temporary upload tokens into permanent asset URIs. Use this to persist files that your app's client has uploaded so they can be referenced later.

This client is only available to apps. Bots cannot create assets.

Access this client via rootServer.dataStore.assets.

Methods

create()

create(request: AssetAppCreateRequest): Promise<AssetAppCreateResponse>

Converts one or more upload tokens into permanent asset URIs. Upload tokens come from your app's client code when users select files through the file picker. Once converted, the resulting asset URIs can be stored and used indefinitely.

Parameters

ParameterTypeDescription
requestAssetAppCreateRequestThe upload tokens to convert.

Returns

Promise<AssetAppCreateResponse>

A promise that resolves to an AssetAppCreateResponse containing a map of tokens to their permanent asset URIs.

Throws

RootApiException with errorCode set to ErrorCodeType.UnAuthenticated if called by a bot instead of an app.

Throws

RootApiException with errorCode set to ErrorCodeType.NoPermissionToRead if the app is not a member of the community.

Example

import {
AssetAppCreateRequest,
AssetAppCreateResponse,
rootServer,
} from "@rootsdk/server-app";

export async function createExample(
tokens: string[],
): Promise<AssetAppCreateResponse> {
try {
// Set up the request
const request: AssetAppCreateRequest = {
tokens: tokens,
};

// Call the API
const result: AssetAppCreateResponse =
await rootServer.dataStore.assets.create(request);

return result;
} catch (error) {
// Detect error
throw error;
}
}

get()

get(request: AssetGetRequest): Promise<AssetGetResponse>

Retrieves metadata for one or more assets by their URIs. Returns information such as the download link, expiry, and preview data for each asset.

Parameters

ParameterTypeDescription
requestAssetGetRequestThe asset URIs to look up.

Returns

Promise<AssetGetResponse>

A promise that resolves to an AssetGetResponse containing a map of URIs to their AssetInformation. URIs that do not match a known asset are omitted from the response map. If none of the URIs match, the map is empty.