Jump to content

Load Picture into Database


Helmut Hort

Recommended Posts

I think you first need to get your image in TStream with TUniFileUpload component, it has Completed event which provides a stream with uploaded file (your image)

Completed(Sender: TObject; AStream: TFileStream);

 

And then load it in the blob image field http://edn.embarcadero.com/article/27462

 

procedure TMainForm.ImageFileCompleted(Sender: TObject; AStream: TFileStream);
var
 BlobField: TField;
 BS: TStream;
begin
 with Query1 do
 begin
   Insert;
   BlobField := FieldByName('picturefield');
   BS := CreateBlobStream(BlobField,bmWrite);
   AStream.SavetoStream(BS);
   Post;
 end;
end;

Link to comment
Share on other sites

  • Administrators

-OR-

 

procedure TMainForm.ImageFileCompleted(Sender: TObject; AStream: TFileStream);
begin
 with Query1 do
 begin
   Append;
   TBlobField(FieldByName('picturefield')).LoadFromStream(AStream);
   Post;
 end;
end;

 

It may be different for Firebird but general rule is to save image stream into blob stream.

Link to comment
Share on other sites

  • 1 year later...

Can you show me, please, what is the content of Query1.SQL
this on your example

//////////////////////////////////////////////////////////////

procedure TMainForm.ImageFileCompleted(Sender: TObject; AStream: TFileStream);
begin
with Query1 do
begin
Append;
TBlobField(FieldByName('picturefield')).LoadFromStream(AStream);
Post;
end;

end;

/////////////////////////////////////////////////////////////

I am trying to Insert one Image on my MySQL the field is type BLOB, but I dont know how can do it,

please help me.

HOw you use the Query1?

Link to comment
Share on other sites

  • 2 weeks later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...