问题
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