本文介绍了EncdDecd的DecodeBase64是否有限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以传入的Base64字符串的大小是否有限制?

Is there a limit on how large of a Base64 string you can pass in?

我正在使用以下内容,并且在创建图片时丢失了一部分底部的。我看到BufferLen约为44000,但DecodeBase64返回的数组大约为24000。

I'm using the following and when my image gets created it's missing a portion of the bottom. I see that BufferLen is ~44000 and yet DecodeBase64 returns about an array of about 24000 items.

BufferLen := (Length(JVal) * 4) div 3;
SetLength(PtrB, BufferLen);
PtrB := DecodeBase64(AnsiString(JVal));

JStream := TStringStream.Create(PtrB);
Jpeg := TJPEGImage.Create;
Jpeg.LoadFromStream(JStream);
Self.JPG := Jpeg;


推荐答案

Soap中的代码没有大小限制EncdDecd单元,而不是使用 AnsiString 数据类型所施加的单元。

There is no size limitation on the code in the Soap.EncdDecd unit, beyond that imposed by the use of the AnsiString data type.

此程序可以成功编码并然后解码一个100MB的字符串即可证明这一点:

This program which successfully encodes and then decodes a 100MB string demonstrates the point:

{$APPTYPE CONSOLE}

uses
  Soap.EncdDecd;

var
  i: Integer;
  plain, encoded: string;

begin
  SetLength(plain, 100*1024*1024);
  for i := 1 to Length(plain) do
    plain[i] := Chr(32+Random(80));
  encoded := EncodeString(plain);
  if plain=DecodeString(encoded) then
    Writeln('passed')
  else
    Writeln('failed');
  Readln;
end.

您的问题几乎肯定在您的代码中,而不是 EncdDecd 单位。

Your problem almost certainly lies in your code rather than the EncdDecd unit.

您的代码可能会更简单。例如:

You code could be quite a bit simpler. For example:

JStream := TBytesStream.Create(DecodeBase64(JVal));
Jpeg := TJPEGImage.Create;
Jpeg.LoadFromStream(JStream);

这篇关于EncdDecd的DecodeBase64是否有限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 07:06