保存Base64编码字符串到磁盘使用德尔福2007年二进制

保存Base64编码字符串到磁盘使用德尔福2007年二进制

本文介绍了保存Base64编码字符串到磁盘使用德尔福2007年二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Base64编码的二进制字符串,它是由第三方供应商发送给我们一个XML文档的一部分,我希望能够保存回其原始文件格式(JPG)。

I have a Base64 binary string that is part of an XML document that is sent to us by a 3rd party supplier, I would like to be able to save it back to its original file format (jpg).

从这个问题\"saving Base64的字符串磁盘作为二进制使用PHP我可以将字符串保存到很少的努力一个jpg,所以我知道该字符串是好形式,是一个JPG文件。

Using the accepted answer from this question "saving a base64 string to disk as a binary using php" I can save the string to a jpg with little effort, so I know the string is in good form and is a JPG file.

但我怎么做到这一点的德尔福2007年?

But how do I do this in Delphi 2007?

找上我发现了如何将Base64编码转换成TByteDynArray,并保存教程网,但它不工作的权利。我也发挥了有关与印的IDDE coderMIME,但没有成功。

Looking on the net I found a tutorial on how to convert the Base64 into a TByteDynArray, and save that, but it doesn't work right. I have also played about with Indy's IdDecoderMIME, but with with no success.

任何一个是否知道如何做到这一点,或者我应该寻找?

Does any one know how to do this, or where I should be looking?

推荐答案

从项目OmniXMLUtils.pas包含以下功能:

OmniXMLUtils.pas from the OmniXML project contains following functions:

function  Base64Decode(encoded, decoded: TStream): boolean; overload;
function  Base64Decode(const encoded: string; decoded: TStream): boolean; overload;
function  Base64Decode(const encoded: string; var decoded: string): boolean; overload;
function  Base64Decode(const encoded: string): string; overload;
procedure Base64Encode(decoded, encoded: TStream); overload;
procedure Base64Encode(decoded: TStream; var encoded: string); overload;
function  Base64Encode(decoded: TStream): string; overload;
function  Base64Encode(const decoded: string): string; overload;
procedure Base64Encode(const decoded: string; var encoded: string); overload;

该Base64De code(字符串,TStream)应该做的伎俩。对于TStream参数,您可以通过它TFileStream的是这样的:

The Base64Decode(string, TStream) should do the trick. For the TStream parameter you can pass it TFileStream like this:

procedure SaveBase64ToFile(const encoded, fileName: string);
var
  fs: TFileStream;
begin
  fs := TFileStream.Create(fileName, fmCreate);
  try
    if not Base64Decode(encoded, fs) then
      raise Exception.Create('Invalid data!');
  finally FreeAndNil(fs); end;
end;

这篇关于保存Base64编码字符串到磁盘使用德尔福2007年二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 07:01