ACtl.getFile
Gets the content of any local file or URL. The maximum file size is only limited by the available RAM.
ACtl.getFile(fileLocation[,returnType]) fileLocation Type: string
Either a URL, data URI, local path or UNC path of the file. It can be relative to the script's location (if there is one). It can also contain placeholders such as <desktop>, <documents> and others.
returnType Type: string Default: 'text'
How to return the file's content.
Returns Type: Promise
Returns immediately. The Promise will resolve with the file content as specified by returnType.
Throws Type: string
Error description if fileLocation cannot be accessed or if the file cannot be interpreted as returnType.
Examples
Get the first Google result for a search term.
let search = 'Olympics' ;
//Download the search results as an HTML fragment
let html = await ACtl.getFile('https://google.com/search?q='+search, 'html') ;
//Get the first search result
let result = html.querySelector('#main a[href^=http][ping]') ;
//Extract the title and URL of the result
let title = result.innerText ;
let url = result.href ;
alert(`TITLE:\n${title}\n\nURL:\n${url}`) ;
Add a text label to a local image file.
let filePath = 'C:/Projects/image.png' ;
//Load the image file as a canvas object
let canvas = await ACtl.getFile(filePath, 'canvas') ;
let ctx = canvas.getContext('2d') ;
//Set text style
ctx.font = '14px arial' ;
ctx.fillStyle = 'blue' ;
ctx.textBaseline = 'top' ;
//Draw the text in the canvas at coordinates [5,5]
ctx.fillText('Hello, world!', 5, 5) ;
//Save the canvas object back to the file
await ACtl.saveFile(filePath, canvas) ;
Obtain Tesla's current stock price from a JSON service.
let url = `http://bloomberg.com/markets2/api/intraday/TSLA:US?days=1&interval=5`;
let data = await ACtl.getFile(url, 'json') ;
alert("TESLA stock price is: $" + data[0].price.slice(-1)[0].value ) ;