PowerShell
PowerShell
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 PowerShell Downloads
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"
$success = $false
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
$http = New-Object Chilkat.Http
$http.KeepResponseBody = $true
$bd = New-Object Chilkat.BinData
$success = $http.DownloadBd("https://www.chilkatsoft.com/images/starfish.jpg",$bd)
$statusCode = $http.LastStatus
if ($success -eq $false) {
if ($statusCode -eq 0) {
# Unable to either send the request or get the response.
$($http.LastErrorText)
}
else {
# We got a response, but the status code was not in the 200s
$("Response status code: " + $statusCode)
# Examine the response body.
$("Response body:")
$($http.LastResponseBody)
}
$("Download failed.")
}
else {
$("Download success, response status = " + $statusCode)
$base64_image_data = $bd.GetEncoded("base64")
$("image data in base64 format:")
$($base64_image_data)
}