I need to convert the $var to a byte array to push it to [convert]::ToBase64String($var)
for upload to a sql DB. All without using Get-Content -file -encoding Byte, as this script is running in Azure without access to any filesystem.
Header contains Auuth bearer token.
$var = (invoke-restmethod -uri ...800x800.png -method -get -headers $head)
Data stream looks like this:
PNG
IHDR Ûph gAMA ±üa cHRM z& ú è u0 ê` : pºQ< bKGD ÿ ÿ ÿ ½§ tIMEã 5Þ IDATxÚìý[°e[}ß?Æ\kgÌçä¹:UÝÕ¥Ôh!]@Rè ÆÌÕ°ÍÃ?øÁðà'¿áðG¶#ÆÆ1!ä ² ...
[System.Array]$myarray = (invoke-restmethod...
$bytes = [System.Text.Encoding]::UTF8.GetBytes($myarray)
$encoded_array = [System.Convert]::ToBase64String($bytes)
Upon decoding of the base64 string, it is sensed as a application/octet instead of an image octet and is broken.
However, running the usual
invoke-restmethod ... ... -outfile c:\test.png
[System.Convert]::ToBase64String (get-content c\test.png -encoding byte)
works, as it should.
To reproduce:
(invoke-restmethod -uri "URI to .png" -method -get )
then play with it till you can get it into an encoded base 64 string.
Wanted result is a base64 string that is the image.
Current result is a base 64 string that is ??? and isn't decoded into anything useful.