web.download
Downloads a file from a URL to the MODLR filesystem, where processes and the MODLR FTP server can reach it.
js
web.download(url, fileName)
web.download(url, fileName, headers) // ^v2.7.228
web.download(url, fileName, headers, method, body) // ^v2.7.228Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | The URL of the file. |
fileName | string | The path to save the file as. |
headers | object | Optional. The request headers, keyed by header name. ^v2.7.228 |
method | string | Optional. The HTTP method: GET, POST, PUT, PATCH or DELETE. Defaults to GET. ^v2.7.228 |
body | object | string | Optional. The request body. An object is sent as JSON, and a string is sent as it is. ^v2.7.228 |
Returns
booleantrue if the file was downloaded, otherwise false.
Examples
js
// Simple download
const success = web.download(
"https://api.example.com/some_file.zip",
"some_file.zip",
);js
// Download with custom headers (e.g. authentication)
const success = web.download(
"https://api.example.com/protected_file.zip",
"protected_file.zip",
{ Authorization: "Bearer your_token" },
);js
// Download the result of a POST request with a JSON body
const success = web.download(
"https://api.example.com/export",
"export.json",
{ "Content-Type": "application/json" },
"POST",
{ reportId: 42, format: "json" },
);