Skip to content

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.228

Parameters ​

ParameterTypeDescription
urlstringThe URL of the file.
fileNamestringThe path to save the file as.
headersobjectOptional. The request headers, keyed by header name. ^v2.7.228
methodstringOptional. The HTTP method: GET, POST, PUT, PATCH or DELETE. Defaults to GET. ^v2.7.228
bodyobject | stringOptional. The request body. An object is sent as JSON, and a string is sent as it is. ^v2.7.228

Returns ​

boolean

true 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" },
);