web.download
Downloads a file to the MODLR Filesystem. This can be accessed via processes using the MODLR Filesystem or through the MODLR FTP Server.
js
web.download(url, filename)The following 2 overloads are available as of ^v2.7.228
js
web.download(url, filename, headers)
web.download(url, filename, headers, method, body)Parameters
url(string): The URL of the file to download.filename(string): The filename to save the downloaded file asheaders(object): An object containing custom headers to include in the request. The keys represent header names, and the values represent the corresponding header values.(optional)method(string): The HTTP method to use for the request (e.g.GET,POST,PUT,PATCH,DELETE). Defaults toGET.(optional)body(object|string): The request body data. It can be an object representing key-value pairs (to be serialized as JSON) or a string with the raw body data.(optional)
Returns
success(boolean): Wether or not the download is successful.
Examples
js
// Simple download
var success = web.download(
"https://api.example.com/some_file.zip",
"some_file.zip",
);
// Download with custom headers (e.g. authentication)
var success = web.download(
"https://api.example.com/protected_file.zip",
"protected_file.zip",
{ Authorization: "Bearer your_token" },
);
// Download the result of a POST request with a JSON body
var success = web.download(
"https://api.example.com/export",
"export.json",
{ "Content-Type": "application/json" },
"POST",
{ reportId: 42, format: "json" },
);