Logotype Sitevision Developer
Log in
Log in

RESTApp resources

Static resources are stored in the /resource folder.

AppResource

The AppResource utility is used to access resources within a RESTApp. RESTApp resources are ONLY open to its enclosing RESTApp, i.e. its content cannot be extracted or downloaded elsewhere.

js
import appResource from '@sitevision/api/server/appResource';

Resources can be accessed in three different ways, where pathToResource is the path to the file in the resource folder.

appResource.getContent(pathToResource)

Returns the resource as a UTF-8 based string.

appResource.getNode(pathToResource)

Returns the resource as a JCR Node (sv:image or sv:file).

appResource.getInputStream(pathToResource)

Returns the resource as a java.io.BufferedInputStream.

js
import router from '@sitevision/api/common/router'; import appResource from '@sitevision/api/server/appResource'; import logUtil from '@sitevision/api/server/LogUtil'; import properties from '@sitevision/api/server/Properties'; router.get('/text', function(req, res) { const message = appResource.getContent('message.txt'); res.json({message: message}); }); router.get('/pdf', function(req, res) { const pdf = appResource.getNode('pdf/info.pdf'); logUtil.info(properties.get(pdf, 'jcr:primaryType')); // sv:file res.sendFile(pdf); });
Did you find the content on this page useful?