Files Snippets
Files snippets to help you work with files within your automations.
# Download a file
We recommend making use of the Download a file step to download files, however, in the event that this does not fit your needs, the following code snippets can be used. These snippets will need to be included in two "Write Javascript" steps, with the second having the "Run in app" setting enabled.
let href = document.querySelector('.download-button-selector').href
let res = await fetch(href)
let text = await res.text()
let base64 = btoa(unescape(encodeURIComponent(text)))
return [[base64]]
let base64 = '[code-data]' // the value returned from the first snippet
let text = Buffer.from(base64, 'base64').toString('utf8')
fs.promises.writeFile("path-to-file", text)
Path to file should be in the following format: C:\\Users\\user\\etc. To learn more about finding an appropriate selector see The Best Custom CSS Selectors to Use for Automations (opens new window).