Page 1 of 1

Reg How To Insert Image File Into MySQL Blob Filed In Delphi

Posted: 19.08.2009, 15:57
by varathasiva
Dear All,
Please advice me
How To Insert Image File Into MySQL Blob Filed In Delphi 7 Coding.
I am saving image into PostgreSQL bytea field through this coding.Its work fine tablenamne.FieldByName('byteafiled') .LoadFromFile('c:\temp.jpg');
When i use this coding MySQL blob means.I am getting Error
Einvalid Graphic With Message Bitmap Image Is Invalid like this.
For database connection and query i am using Zeos Access Component.Please help me.How to solve this problem.Advance thanks to all.
Thanks & Regards
Siva

Posted: 20.08.2009, 02:38
by manz
Hi varathasiva ..

In MySQL you may used LONGBLOB instead BLOB data type.

for the saving image you may try this :

Code: Select all

var
  J: TJPEGImage;
begin
  J := TJPEGImage.Create;
  J.LoadFromFile('C:\Manz\Projects\Web\hrms\public_html\images\photo\1357a.jpg');
  zTable2.Active := true;
  ztable2.Append;
  ztable2.FieldByName('foto').Assign(J);
  ztable2.Post;
  FreeAndNil(J);
end;
Hopefully work, but you may not use at Delphi 2009 with Zeos 7 beta version, because this would be JPEG Error maybe Bad Format.

:D

Thanks
Man'z

Posted: 20.08.2009, 08:28
by varathasiva
Dear Man'z,
Thanks for your quick repy.
I am using same code wht u sent to me.

var
J: TJPEGImage;
begin
if OpenPictureDialog1.Execute then
begin
J.LoadFromFile('c:\temp\ok1.jpg');
student.FieldByName('stu_photo').Assign(J);
student.Post;
FreeAndNil(J);
end;
end;
When i complier comes this line
J.LoadFromFile('c:\temp\ok1.jpg');
Its showing Access Violation Error.Please help me.How to solve this problem.
Im waiting for ur reply.Advance Thanks to u.
Thanks & Regards
Varathasiva

Posted: 20.08.2009, 08:37
by manz
Dear Varathasiva,

you miss one line of it :

J := TJPEGImage.Create;

before you can do J.LoadFromFile(....

Thanks
Man'z