HttpGetFile
Function | HttpGetFile | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
Action | A built-in function for downloading content (resources) over HTTP(S) via the Tachyon Background channel, or from an external web-server. If the file cannot be downloaded, or the downloaded content does not match the hash and size supplied, an error occurs and the instruction is terminated. The file is downloaded into a randomly named sub-directory of TemporaryDirectory. From version 5.1 onwards, the location of TemporaryDirectory is a configuration setting of the 1E Client. The sub-directory and file is deleted when the instruction ends. If you want to keep the file, make the instruction copy it to a permanent location. The following table shows the OS-specific defaults used if the setting is omitted, blank, or invalid. The default is recommended.
Nomad integrationIf 1E Nomad is available, it will optimize the download, storing a local copy of the file in the Nomad cache, with cache priority 1 and is subject to normal Nomad cache management. | |||||||||
Parameters |
It is a runtime error if the status code from a GET request on the full absolute URL is not 200. Note" NoteWhen an absolute URL is specified and the schema is 'https' then the endpoint requesting the resource will attempt to verify the entire certificate chain of the resource as normal. This can fail if the endpoint does not recognize all the links in the chain of trust. The rules of checking are more rigorous than some browsers, which are often relaxed about the very root of the chain if it is signed using a sha1 algorithm. This means whilst a browser may download the resource and display it, the endpoint might actually complain about the validity of the root Certificate Authority certificate. To resolve this, you need to get hold of the public key for the root certificate and:
| |||||||||
| ||||||||||
| ||||||||||
| ||||||||||
| ||||||||||
| ||||||||||
Return values |
WarningThis is a temporary file that persists only while the instruction is live. When the instruction ends the file will be deleted. If you want to keep the file, make the instruction copy it to a permanent location. | |||||||||
Example | A common use for this function is to download a script which can then be executed locally. Example - download and execute a script /* Download the script. Since we specify a partial URL (just the filename), the full URL is built by combining the specified URL with the root of the Tachyon Background channel. Note that because HttpGetFile is a built-in function, there is no need to specify a Module name */ @resource1 = HttpGetFile(URL:"MyCustomScript.ps1", Size:2137, Hash:"e0b5bb08b68ed4cdd73d035a775458e34bce1d68ec93a11defa62ca25e3d7037"); /* @script now contains a single row with one column named FilePath, so can be passed directly to the Scripting module */ @result = Scripting.Run(Language: "PowerShell", Script: @resource1, InterpretAsJson: true); To download content from an external web-server, you can instead set the URL property to the full URL of the file to be downloaded. Example - downloading content from an external URL /* Download file from web server */ @resource1 = HttpGetFile(URL:"http://webserver.acme.com/MyFile.jpg", Size:73355, Hash:"c9411ef157a1b9e7d8418d0d9297b8df3f633b6a1b2250d735c9b5cd32f1f795"); /* Build command line to copy temporary downloaded file to final location */ @cmd = SELECT "cmd.exe /c copy " || FilePath || " C:\\Pictures\\MyFile.jpg" AS CommandLine FROM @resource1; /* Run the command built above */ NativeServices.RunCommand(CommandLine: @cmd.CommandLine); /* Downloaded file will now be in C:\Pictures\MyFile.jpg */ | |||||||||
Platforms |
| |||||||||
Notes |