Skip to content

Resource

A Resource Business Object holds a file, such as an image, a PDF or a template, inside the app. In code, each Resource is a read-only object under This.$Resources.<ResourceName> with the file’s metadata and URL, and, on the server, functions that read its content.

Availability: Everywhere

This.$Resources.<ResourceName>

Resources are grouped under the $Resources namespace. This.<ResourceName> does not work; the $Resources. part is required.

Whether a Resource exists outside server-side code depends on its client availability setting:

Client availabilityServer-side codeClient-side and shared code
noneyesnot present
downloadableyesproperties only
builtinyesproperties only (see the note on getDataBase64())

The object’s type is ResourceDefinition<EL, Avail>, where EL is the side the code runs on and Avail the Resource’s client availability (full on the server).

getDataBuffer?: () => Promise<Buffer>

Returns the Resource’s content as a Node.js Buffer. It is declared as an optional member of the Resource object.

Returns: Promise<Buffer> · Availability: Server

const template = await This.$Resources.InvoiceTemplate.getDataBuffer!()
getDataString?: () => Promise<string>

Returns the Resource’s content decoded as UTF-8 text. It is declared as an optional member of the Resource object.

Returns: Promise<string> · Availability: Server

Note

In client-side code, getDataString is also typed for Resources whose client availability is builtin, but it is never generated there: on the client it is undefined.

getDataBase64?: () => Promise<string>

Returns the Resource’s content as a Base64 string. It is declared as an optional member of the Resource object.

Returns: Promise<string> · Availability: Server

Note

In client-side code, getDataBase64 is also typed for Resources whose client availability is builtin, but it is never generated there: on the client it is undefined. To use a Resource’s content on the client, load it from relativeUrl.

resourceType: ResourceType

The Resource’s file type, as selected on the Resource, for example 'application/pdf', 'image/png', 'text/csv' or 'application/octet-stream'.

Type: ResourceType · Availability: Everywhere

mimeType: string

The MIME type the Resource is served with: the override MIME type if one is set, otherwise resourceType.

Type: string · Availability: Everywhere

fileName: string

The Resource’s file name.

Type: string · Availability: Everywhere

relativeUrl: string

The path at which the app serves the Resource, starting with /.

Type: string · Availability: Everywhere

absoluteUrl: string

The full URL of the Resource: the instance’s public URL (System.$Config.Environment.publicUrl) followed by the Resource’s path.

Type: string · Availability: Everywhere

  • Resource