[英]How to encode file of any type into base64 string and then decode it into file again using Lazarus/Delphi?
[英]Delphi 7 - Decode base 64 string to a file
我试图找到一种方法来解码base64字符串,然后使用Delphi 7(此特定的Delphi版本)将其保存到文件中。
base64字符串本身是一个PDF文件,作为HL7消息的一部分编码为base64。 我发现的几乎所有示例都与Delphi 7不兼容。
有人可以帮忙吗?
更新:
正如Remy Lebeau建议使用TidDecoderMIME。 这是解码并保存到二进制文件的正确方法吗?
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字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.