Send files to Mysql in Blob

Asked

Viewed 27 times

-1

good morning.

Does anyone know how to send exe and csv files to Mysql using Delphi?

I didn’t find much in it. I need to save CSV files in the table but when I import by the test below the file size is much smaller than the original.

imgfoto.Picture.LoadFromFile('C:\1\1.jpeg');

imagem := Tmemorystream.Create;

imgfoto.Picture.Graphic.SaveToStream(imagem);

FDQuery1.Open;

FDQuery1.First;

if FDQuery1.Locate('LJ_NOME', 'AAAAAAAA', []) then

begin

FDQuery1.Edit;

TBlobField(FDQuery1.FieldByName('LJ_BLOB')).LoadFromStream(imagem);

end;

I tried to convert CSV and EXE to JPEG and send via stream, it does not recognize because it is not image. I tested via memo, but it carries the first line only.

How do I upload files to Mysql?

1 answer

0

Use "Loadfromfile" from the field. Below is an example of the form used.

Considering the following table:

CREATE TABLE `arquivos` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `arquivo` BLOB NULL DEFAULT NULL,
    PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8_bin'
ENGINE=InnoDB;

I did it this way:

FDQuery1.Insert;
FDQuery1arquivo.LoadFromFile('<Caminho para o arquivo>');
FDQuery1.Post;

Sample code

Browser other questions tagged

You are not signed in. Login or sign up in order to post.