Topic: [SOLVED]-Scratching my head over this one... Save image by script
Hello Dmitry and all MVD fans,
I known how to load an image FROM database TO a component in a form or extract an image FROM database and save it to a file.
Extracting the file would be done with something like :
procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
var
s: string;
begin
s := SaveFileFromDataBase('tablename', 'fieldname', Form1.TableGrid1.dbItemID); // save file to disk and get filename in system temp folder
OpenFile(s); // open file
CopyFile(s, 'C:\'+ExtractFileName(s)); // copy the file to disk C:\
end;
But what I do not known is how to to the reverse : how do you, by script, save a file into database ?
I've tried to use TJpegimage, TBlobField, TMemoryStream to load from file into memory and save but no success. The missing link is in the query :
SQLexecute('INSERT INTO img(id_asset,asset_img,asset_img_filename) VALUES (1,'+ms.LoadFromFile('test.jpg')+',"test.jpg")');
I just don't known how to pass the TImage variable to the query.
I've tried with parametrised queries as well, but failed miserably. Any clue for me ?
By the way, I'm asking because I have a loop scraping numerous web pages, and I don't want to load each image in a DBImage component and clicking on the button to save each image one by one.
Thanks and cheers
Mathias
Each time I get a divorce, I keep the house
Zaza Gabor