Decode function

I am trying to download a file via a API. I have a problem decoding the base64 stream. When a use the decode function a export the file (MS Word and PDF) de files are corrupt. The PDF file can be opend but has no tekst and the DOCX file is corrupt accoding to MS WORD.
(I tried de BASE64 and BASE64URL paramater)

Decode with Powershell works, but a hope EM could do it.

Hi Jan,

How do you do it with PowerShell? Can you post the script?

The script I use:

Stel het pad naar het base64 bron en doelbestand in

$bronBestand = "\gn.karelstad.nl\Documenten\sandj1\My Documents\Handtekening outlook voorbeeld BASE64.docx"
$doelBestand = $bronBestand.replace(" BASE64","")

$base64String = Get-Content -Path $bronbestand -Raw
$decodedBytes = [Convert]::FromBase64String($base64String)

Save the decoded data to the output file

[IO.File]::WriteAllBytes($doelBestand, $decodedBytes)

Write-Host "Decoded data saved to $doelBestand"