OK, well this is driving me nuts, lol.
I have a Base64 string and am trying to decode it into a TMemoryStream using TIdDecoderMIME.
My current code is as follows:
Var MStream:TMemoryStream; Decoder:TIdDecoderMIME;
begin
Decoder := TIdDecoderMIME.Create(nil);
MStream := TMemoryStream.Create;
Decoder.DecodeToStream(BSting,MStream);
end;
Where BString = My Base64 string.
Now when the code is ran, I get an error message saying "Uneven size in DecodeToString."
Any ideas?
Any help is greatly appreciated. Thanks.
You're passing to the DecodeToStream
function a Base64 string whose length is not a multiple of 4. In other words, the string you're passing is invalid.
Base64 strings are normally padded with trailing "=" signs to make sure their length is a multiple of 4.
Some decoders will try to correct for the missing padding chars while others will not. See the StackOverflow question "Remove trailing “=” when base64 encoding"
The TIdDecoderMime object validates the input by making sure it is a multiple of 4 - which it will be if the padding chars are included in the input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With