How to save a binary file (image) from URL address

The following script allows to download and save to disk a binary file from specific URL address. The Microsoft HTTP request technology is used in the script in order to download the binary file from URL address. The ADO technology is used for saving the contents of the file to disk. Both technologies are launched by the CreateObject method.
The example of download and save of the image generated by Web camera:
The script can be included into the application for example in the PmaTimer.onTick event, in the PmgButton.onButtonUp event etc.
VBScriptSelect and copy to clipboard

Dim oHttp, oStream, sUrl, sSavePath
sSavePath = Pm.DiscGetPath("#appres:") & "MyPicture.jpg"
sUrl = ""

Set oHttp = CreateObject("Microsoft.XMLHTTP")

oHttp.Open "GET", sUrl, false, "username", "password"   ' username and password only if proxy server
oHttp.setRequestHeader "Content-Type", "image/multipart"
If oHttp.readyState = 4 And oHttp.status = 200 Then
Set oStream = CreateObject("")
oStream.type = 1   ' 1=adTypeBinary
oStream.write oHttp.responseBody
oStream.savetofile sSavePath, 2   ' 2=adSaveCreateOverWrite, 1=adSaveCreateNotExist
Set oStream = Nothing
End If
Set oHttp = Nothing
PROMOTIC 9.0.25 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
- How to save a binary file (image) from URL address
© MICROSYS, spol. s r. o.