Fixed (almost, still a problem with 5 Mb files - eg: 4.987.904 should go smoothly on MEDIUMBLOB instead
Lost Connection during query... to understand, already with 2.7 Mb files you
has the exception).
in MySql
{
TINYBLOB : maximum length of 255 bytes
BLOB : maximum length of 65,535 bytes
MEDIUMBLOB : maximum length of 16,777,215 bytes
LONGBLOB : maximum length of 4,294,967,295 bytes
}
procedure Tfrm_Articoli.InserisceImmagine(sFile: string);
var jp:TJpegImage;
MemStream: TMemoryStream;
begin
sFile := '<foto da inserire>';
FDQuery1.Open;
FDTransaction1.StartTransaction;
sFile := '<foto da inserire>';
FDTransaction1.StartTransaction;
try
jp := TJpegImage.Create;
jp.LoadFromFile(sFile);
FDQuery1.Active := true;
FDQuery1.Insert;
FDQuery1.FieldByName('immagine1').Assign(jp);
FDQuery1.Post;
FreeAndNil(jp);
FDTransaction1.Commit;
except
FDTransaction1.RollBack;
end;
MemStream := TMemoryStream.Create;
sFile := '<foto da inserire>';
Image1.Picture.LoadFromFile(sFile);
Image1.Picture.SaveToStream(MemStream);
MemStream.Seek(0,0);
FDQuery1.SQL.Text := 'INSERT INTO tb_test (immagine1) VALUES (:img)';
FDQuery1.ParamByName('img').LoadFromStream(MemStream, ftBlob);
FDQuery1.ExecSQL;
..
end;