简体   繁体   中英

Delphi 7 - Decode base 64 string to a file

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;

Delphi随Indy一起提供,Indy具有TIdDecoderMIME类,用于解码base64字符串。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM