[英]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.