Delphi 7 - Decode base 64 string to a file
base64, decode, delphi, delphi-7
Solution
Delphi ships with Indy, which has a `TIdDecoderMIME` class for decoding base64 strings.
Problem
I am trying to find a way to decode base64 string and then save it to a file using Delphi 7 (this specific Delphi version). The base64 string it-self is a PDF file, encoded to base64 as part of HL7 message. Almost all examples that I found were not compatible with Delphi 7. Anyone can help? UPDATE: As suggested by Remy Lebeau to use TidDecoderMIME. Is this the correct way to decode and save to binary file? ` var MStream:TMemoryStream; Decoder:TIdDecoderMIME; Base64: string; begin Decoder := TIdDecoderMIME.Create(nil); MStream := TMemoryStream.Create; Base64 := 'abcd1234'; Decoder.DecodeToStream(Base64,MStream); MStream.SaveToFile('example.pdf'); FreeAndNil(Decoder); FreeAndNil(MStream); end;`