Is there a limit to DecodeBase64 from EncdDecd?

拥有回忆 提交于 2019-12-24 03:08:01

问题


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

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;

回答1:


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

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.

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);


来源:https://stackoverflow.com/questions/15936093/is-there-a-limit-to-decodebase64-from-encddecd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!