Basics
Features
Best Practices
Addon Development
Related Docs
Dark Mode

#Assets

Assets are accessed the same way other files in the filesystem are. You can use whatever packages or methods you wish to read, write, and delete these files. Unlike other things your Addon creates and manages, Assets are not sandboxed to your Addon so care must be taken not to overwrite, delete, or otherwise conflict with files created by the user or other Addons.

// store assets with static-cms-addon and node fs
import cms from 'static-cms-addon'

let assetPath = await cms.getAssetPath() // ex: /home/ubuntu/sites/my-site/local/cms/asset
let codePath = await cms.getCodePath() // ex: /home/ubuntu/sites/my-site/local/cms/addon/my-addon/code

fs.mkdirSync(`${assetPath}/my-addon/docs`, {recursive: true})
fs.cpSync(`${codePath}/templates/sample.pdf`, `${assetPath}/my-addon/docs/sample.pdf`)

// store assets with axios and curl
let response = await axios.get(`http://localhost:${cmsPort}/api/addon/${addonId}/state`)
let assetPath = response.data.cms.assetPath

execSync(`curl http://example.com/documents.zip -o ${assetPath}/documents.zip`)