How to download files from database using Free Pascal/Lazarus

After uploading files in the previous example into database, now we need to download that files:

Create new Lazarus project to open and browse Photos table in this form:

Download button will prompt you to specify where to download the file.

Write this code in Download button’s OnClick:

procedure TForm1.Button3Click(Sender: TObject);
  BlobStream : TStream;
  M: TFileStream;
  SaveDialog1.FileName:= SQLQuery2.FieldByName('FileName').AsString;
  if SaveDialog1.Execute then
    BlobStream := SQLQuery2.CreateBlobStream(SQLQuery2.FieldByName('Content'),bmread);
    M:= TFileStream.Create(SaveDialog1.FileName, fmCreate);
    BlobStream.Position:= 0;
    M.CopyFrom(BlobStream, BlobStream.Size);



7 thoughts on “How to download files from database using Free Pascal/Lazarus

  1. Pingback: How to upload files into database using Free Pascal/Lazarus « Free Pascal Answers

  2. we can do it with one line :(if we use DBImage1, see my message in previous example )

  3. Hello, I want to make you a question: What kind of report tool are you using in your software development?
    I know that exist a report tool called Fortes4Lazarus, but i would like to see if there is another good tool.

  4. I’m using Fortes report, and I’ve used LazReport, but LazReport has an issues while designing reports under linux.
    Make sure to get the latest version of Fortes report

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s