Okay guys,
It's working.

Thanks SO much to everyone who helped me get it going - the final one
(it turns out) had nothing to do with the base64 code - while I was
restructuring for the idea of saveing as I decode I had to change
GetData function - and I forgot to return the result -the files were
empty because I wasn't giving it any input. Once I fixed that, it
worked beautifully - and now it has all the abilities I need for the
next level.

Ciao
A.J.

On 5/17/07, A.J. Venter <[EMAIL PROTECTED]> wrote:
Hiya Bram
Well I decided to follow your advice. I changed my structure to encode
straight from file (using a tfilestream) and also to decode directly
TO a file (completely removing the stringlists).

But now my files just remain empty - despite me being very carefull to
free the tfilestream...
isn't tfilestream supposed to write to disk as soon as you store ?
I have two reasons I don't want to load from memorystreams btw.
1) Because that means tpicture has no means of identifying types - it
seems to only work for XPM formatted images
2) More importantly - my program will have literally THOUSANDS of
remote accessing clients using the images, I want them to keep local
caches and ONLY retrieve an image from the DB if it has been changed
(hence my gratitious use of timestamping)

A.J.

The new decode function looks like this:
Procedure DecodeB64(S,FileName:String);
Var
  b64decoder: TBase64DecodingStream;
  S1 : TStringStream;
  SaveTo : TFileStream;
begin
   S1 := TStringStream.Create(S);
   SaveTo := TFileStream.Create(FileName,fmcreate OR fmOpenWrite);
   b64decoder := TBase64DecodingStream.Create(S1);
      Try
        b64decoder.read (SaveTo,b64decoder.Size);
      except
            DebugLn('Stream error in DecodeB64');
      end;
   S1.Free;
  b64decoder.Free;
  SaveTo.Free;
end;


On 5/17/07, Bram Kuijvenhoven <[EMAIL PROTECTED]> wrote:
> A.J. Venter wrote:
> > Var S1,S2,S3: TStringList;
> >    FN : String;
> > begin
> > S1 := TStringList.Create;
> > S2 := TStringList.Create;
> > S3 := TStringList.Create;
> >  If OpenPictureDialog1.Execute then
> >     Begin
> >          S1.LoadFromFile(OpenPictureDialog1.FileName);
> >          S2.Add(EncodeB64(S1.Text));
> >          S3.Add(DecodeB64(S2.Text));
> >          FN :=
> > 
GetTempFileName(GetTempDir,'blah')+ExtractFileExt(OpenPictureDialog1.FileName);
> >
> >          ShowMessage(FN);
> >          S1.SaveToFile(FN);
>
> You are saving the wrong thing here :)
>
> >          Image1.Picture.LoadFromFile(FN);
> >     end;
> > end;
>
> Anyway, StringLists are not meant to store binary data. In this case, 
TStringList converts #10 to #10#13 (on Windows), messing up your PNG file (even 
without letting base64 touch it at all!).
>
> BTW, you can let the TBase64EncodingStream operate on a TFileStream, and I 
guess Image1.Picture can also load from a stream directly instead of from a 
temporary file; then I recommend to use a TMemoryStream to hold the decoded image 
data.
>
> The base64 decoding itself fails with FPC 2.0.4, but works with 2.3.1 
(trunk). If you want to compile with 2.0.4., you can copy the base64 unit from 
SVN. Of course the 2.0.4 version could also work when used in a certain way, but I 
do not know how.
>
> Bram
>
> _________________________________________________________________
>      To unsubscribe: mail [EMAIL PROTECTED] with
>                 "unsubscribe" as the Subject
>    archives at http://www.lazarus.freepascal.org/mailarchives
>


--
A.J. Venter
CEO - OutKast Solutions C.C.
http://www.outkastsolutions.co.za
Cell: +27 83 455 9978
Fax: +27 21 413 2800
Office: +27 21 591 6766



--
A.J. Venter
CEO - OutKast Solutions C.C.
http://www.outkastsolutions.co.za
Cell: +27 83 455 9978
Fax: +27 21 413 2800
Office: +27 21 591 6766

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to