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:
VBScriptSelect and copy to clipboard
Dim oHttp, oStream, sUrl, sSavePath
sSavePath = Pm.DiscGetPath("#appres:") & "MyPicture.jpg"
sUrl = "http://sah.x3w.cz/dl/lanovka.jpg"
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"
oHttp.send
If oHttp.readyState = 4 And oHttp.status = 200 Then
Set oStream = CreateObject("adodb.stream")
oStream.type = 1
' 1=adTypeBinary
oStream.open
oStream.write oHttp.responseBody
oStream.savetofile sSavePath, 2
' 2=adSaveCreateOverWrite, 1=adSaveCreateNotExist
Set oStream = Nothing
End If
oHttp.abort
Set oHttp = Nothing