VBScript
VBScript
Download Image (JPG, GIF, etc.) to Base64
See more HTTP Examples
Demonstrates how to download an image, or any type of file, to get the data in base64 encoding format.Chilkat VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
set http = CreateObject("Chilkat.Http")
http.KeepResponseBody = 1
set bd = CreateObject("Chilkat.BinData")
success = http.DownloadBd("https://www.chilkatsoft.com/images/starfish.jpg",bd)
statusCode = http.LastStatus
If (success = 0) Then
If (statusCode = 0) Then
' Unable to either send the request or get the response.
outFile.WriteLine(http.LastErrorText)
Else
' We got a response, but the status code was not in the 200s
outFile.WriteLine("Response status code: " & statusCode)
' Examine the response body.
outFile.WriteLine("Response body:")
outFile.WriteLine(http.LastResponseBody)
End If
outFile.WriteLine("Download failed.")
Else
outFile.WriteLine("Download success, response status = " & statusCode)
base64_image_data = bd.GetEncoded("base64")
outFile.WriteLine("image data in base64 format:")
outFile.WriteLine(base64_image_data)
End If
outFile.Close