CodePudding user response:
What sounds like the attribute image or large objects or binary,,,,General subdirectories or saved to the server is ok, just save it in the database of the relative path
CodePudding user response:
Thank you, I also know that the relative directory saved in the database approach, but I still want to know is there any way of directly stored in the database?CodePudding user response:
Using the image field,With a stream file saved to the field,
CodePudding user response:
The path of the save imageCodePudding user response:
In Delphi is used in the query of the blob data type into the file, and then deposited in the corresponding field in the database (image or any large objects or binary)CodePudding user response:
TBlobField (DataSet. FieldByName (' field name). The LoadFromFile (full filename);CodePudding user response:
1. The selection of image data and save theProcedure Tform1. SelectimageClick (Sender: TObject);//select image
The begin
If openpicturedialog1. Execute then
Image1. Picture. LoadFromFile (openpicturedialog1 FileName);
The end;
Procedure Tform1. SavetodbClick (Sender: TObject);//save the image to the database
Var
Ext: string;
The begin
If image1. Picture. Graphic & lt;> Nil then//avoid the no image save image1 error
The begin
Adotable1. Edit;
Adotable1. FieldByName (myimage.png). Assign (image1. Picture. Graphic);
//the following records to the database of image formats
Ext:=extractfileext (openpicturedialog1. FileName);//remove the file extension
If uppercase (ext)=. BMP THEN
Adotable1. FieldByName (isbmp). The VALUE: type=1//BMP image data
ELSE IF (UPPERCASE (EXT)=. JPEG) OR (UPPERCASE (EXT)=. JPG) THEN
Adotable1. FieldByName (isbmp). The VALUE:=0; Type//JPEG image data
ADOTABLE1. Post;
The end;
The end;
2. Read and display image data
Procedure Tform1. ADOTable1AfterScroll (DataSet: TDataSet);//ADOTable1 AfterScroll event method program
Var
Jpegimage: tjpegimage;
The begin
Image1. Picture. Graphic:=nil;
//below BMP, JPEG two kinds of image data required to separate
If adotable1. Fieldbyname (isbmp). Asstring=1 then/type/BMP image data
Image1. Picture. The bitmap. The Assign (adotable1 fieldbyname (myimage.png))
//bitmap in the statement above cannot be as the graphic, otherwise will go wrong
Else if adotable1. Fieldbyname (isbmp). Asstring=0 then/type/JPEG image data
The begin//begin2
Jpegimage:=tjpegimage. Create;//by jpegimage will image display in image1, otherwise will go wrong
Try
Jpegimage. Assign (adotable1. Fieldbyname (myimage.png));
Image1. Picture. Graphic:=jpegimage;
The finally
Jpegimage. Free;
The end;//end try
The end;//end begin2
The end;
Note: don't forget to unit in JPEG file interface section USES statement reference unit,
The above code in DELPHI6.0 + SQL (or ACCESS or PARADOX) database run through,
CodePudding user response:
IMAGE format is selected IMAGE in the database, storage and reading is commonly with flow, I give you a piece of code, respectively is the function of the upload attachment and download attachment:Upload:
Var
Fs: TFileStream;
FtpStr: string;
The begin
FtpStr:=edt3. Text;//here is mainly to use DlgOpen controls selected filename
Fs:=Tfilestream. Create (FtpStr Fmopenread);
Qry1. Close;
Qry1. SQL. The Clear;
Qry1. SQL. The Add (' select * from document management);
Qry1. Open;
Qry1. Append;
Qry1. FieldByName (' theme '). AsString:=edt1. Text;
Qry1. FieldByName (' categories'). AsString:=cbb1. Text;
Qry1. FieldByName (' attachment size) AsString:=FileSizeStr;
Tblobfield (qry1 FieldByName (' attachments')). LoadFromStream (fs);//here is the way of save attachment
Qry1. Post;
Fs. Free;
Download:
TBlobField (qry1 FieldByName (' attachments')). SaveToFile (dlgSave1. FileName);
More than hope to help you!
CodePudding user response:
Analysis of detailed aboveCodePudding user response:
The image field, blobfieldWith a stream file saved to the field in the...
CodePudding user response:
I had contact with a images saved in the database of the system, the database is SQL server, run after a few months time, seemingly efficiency become unbearable, stored or recommended directoryCodePudding user response: