Home > Back-end >  How to images stored in the database file?
How to images stored in the database file?

Time:09-28

In programming, I need to be stored in the database image files, how to do? (I use a database for SQL SERVER, can explain the properties of the stored image field, best solution)), thank you!

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 image

CodePudding 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 the

Procedure 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 above

CodePudding user response:

The image field, blobfield
With 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 directory

CodePudding user response:

refer to the eighth floor changfenglee response:
IMAGE format is selected IMAGE in the database, storage and reading is usually in flow way, I'll 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,...
this is very good

CodePudding user response:

1, SQL can save the IMAGE data, save the IMAGE in the field, the local SQL can read and write properly, if the SQL server, will be read out,
2, it is suggested that a large image cannot be saved in the database, otherwise, the data runs slowly,

CodePudding user response:

This is the mechanism of SQL SERVER problem, I use the other problems of the slow database does not exist.

CodePudding user response:

Pictures or save in the form of files, or database will slowly,

CodePudding user response:

To save image types, data in binary, remove data slower, advice to save image address,

CodePudding user response:

The efficiency problem need to be considered!!

CodePudding user response:

If direct deposit, saved in a binary way, typically save path

CodePudding user response:

Images stored in the database, can be Shared, but to run, read image data (big) is slow, there is a way to, first of all, the image stored in the database, at the same time in the local disk, save the image file, when there are local image file, read the local image data, if there is no image data read database, and stored in a local disk, so, to run faster,

CodePudding user response:

The Internet a lot of ha ha LZ must be solved

CodePudding user response:

Save the road king is the best, with the flow is needed to turn the binary turn ~ ~ ~ read out also

CodePudding user response:

Use TBlodFiled, whatever file, all this is stored in the load flow field,nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related