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
How to reach it
Section titled “How to reach it”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 availability | Server-side code | Client-side and shared code |
|---|---|---|
none | yes | not present |
downloadable | yes | properties only |
builtin | yes | properties 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).
Functions
Section titled “Functions”getDataBuffer()
Section titled “getDataBuffer()”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()
Section titled “getDataString()”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()
Section titled “getDataBase64()”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.
Properties
Section titled “Properties”resourceType
Section titled “resourceType”resourceType: ResourceTypeThe 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
Section titled “mimeType”mimeType: stringThe MIME type the Resource is served with: the override MIME type if one is set, otherwise resourceType.
Type: string · Availability: Everywhere
fileName
Section titled “fileName”fileName: stringThe Resource’s file name.
Type: string · Availability: Everywhere
relativeUrl
Section titled “relativeUrl”relativeUrl: stringThe path at which the app serves the Resource, starting with /.
Type: string · Availability: Everywhere
absoluteUrl
Section titled “absoluteUrl”absoluteUrl: stringThe full URL of the Resource: the instance’s public URL (System.$Config.Environment.publicUrl) followed by the Resource’s path.
Type: string · Availability: Everywhere
Related
Section titled “Related”- Resource