dkeene Posted April 6, 2020 Share Posted April 6, 2020 Hi, All I have a mysql database with a table with a Blob field for storing images. If I place images in the control through DB workbench, I can view them nicely on the form. I am able to upload a file using TFileUpload, and when it completes, I successfully see it on a form UniImage. I would like to save this in the database. procedure TfmTableEdit.UniFileUpload1Completed(Sender: TObject; AStream: TFileStream); var aWinControl: TWinControl; blob: TStream; begin //check if a selected image aWinControl:=MFetchselectedControl(self.UniContainerPanel1); //FETCHES APPROPRIATE UNIDBImage CONTROL. if aWinControl=nil then begin ShowMessage('No Control Selected.'); end else if aWinControl.ClassName='TUniDBImage' then begin //SELECTED CONTROL is UniDBImage. Self.UniImage1.LoadFromStream(AStream); //places image on UniImage1 to confirm. blob:=Self.FDQuery1.CreateBlobStream(Self.FDQuery1.FieldByName(TUniDBImage(aWinControl).DataField), bmWrite); //creates BLOB to Datafield. blob.Position:=0; Self.UniImage1.Picture.Graphic.SaveToStream(blob); //Saves image from UniImage1 to Datafield. (??????) TUniDBImage(aWinControl).Refresh; end; While I can see the image on the UniImage1 control, and blob.Position after the SaveToStream(blob) is an appropriate number, I see no change in the Selected Control, nor is the field changed. Any suggestions? Thank you! Doug Quote Link to comment Share on other sites More sharing options...
dkeene Posted April 6, 2020 Author Share Posted April 6, 2020 Anyone please? I am able to do this: var blob: TStream; begin Self.UniCanvas1.LoadFromFile('building_big.jpg'); blob := Self.FDQuery1.CreateBlobStream(Self.FDQuery1.FieldByName('facilitylogo'), bmWrite); UniCanvas1.SaveToStream(blob, tiBMP); blob.Free; but not this (on completion of an uploaded bitmap file.) //upload completed and verified procedure TfmTableEdit.UniFileUpload1Completed(Sender: TObject; AStream: TFileStream); var blob: TStream; aField: TField; begin Self.UniCanvas1.LoadFromFile(AStream.FileName); //places in canvas aField:=Self.FDQuery1.FieldByName('facilitylogo'); blob:=Self.FDQuery1.CreateBlobStream( aField , bmWrite); Self.UniCanvas1.SaveToStream(blob, tiBMP); blob.free; Doug Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.