1 (edited by teco049 2017-03-08 14:44:29)

Topic: Question about DBFiles

For a project I need to know if I can store a selected file via script into the database or only by action.
.
As attached, the file storage is included in the same page where the project information is stored. The old application, which should be replaced, has worked in the same way and the new application should work like the old.
.
Before storage I need to find out the size for the file to add. Depending on the size the File will be stored inside the database or outside on a file folder.
.
Is there a way to store the file via script to the Database or read out the file from the database to a folder via script?
.
Attached is a sample from the project planning.
.
.
Thanks for helping.
.
.
UPDATE:
Storing without scrip is working, but there is no relation to the main record in the database.... How can this be changed?

Post's attachments

Attachment icon Test_DBFile.zip 4.17 kb, 428 downloads since 2017-03-08 

Re: Question about DBFiles

Hello.


I have added function GetFileSize to get file size.
Please download latest beta version:
https://www.dropbox.com/s/xf20ksdbdgj6w … b.zip?dl=0



Also I have attached an example, how to store file to database using script:

Post's attachments

Attachment icon SaveFileToDatabase script.zip 326.41 kb, 755 downloads since 2017-03-09 

Dmitry.

Re: Question about DBFiles

DriveSoft wrote:

Hello.


I have added function GetFileSize to get file size.
Please download latest beta version:
https://www.dropbox.com/s/xf20ksdbdgj6w … b.zip?dl=0



Also I have attached an example, how to store file to database using script:

Dear Dmitry,
.
Thank you for your help.
.
I have still a little problem.
When I have the file dialog on the same form where I have the table with the stored files, I can not use the store button at the file dialog. It shows no files to store.
I have tried to expand your example with a way to store a file from Database back to Disk by script.
Please take a look at the expanded version. I think that I have missed something or have read the wrong information from Embarcadero about the used functions...
.
Thank you.

Post's attachments

Attachment icon SaveFileToDatabase script_ADDED.zip 558.37 kb, 483 downloads since 2017-03-09 

Re: Question about DBFiles

Check out this script to store a file from datanase to disk:

procedure Form1_Button6_OnClick (Sender: string; var Cancel: boolean);   //GET STORED FILE BACK TO DISK
var
    sFileName: string;
    sTempFile: string;
    SaveDialog: TSaveDialog;
begin
    SaveDialog := TSaveDialog.Create(Form1);
    SaveDialog.FileName := ExtractFileName( SQLExecute('SELECT somefile_filename FROM test WHERE id='+Form1.TableGrid1.sqlValue) );
    if SaveDialog.Execute then
    begin
        sFileName := SaveDialog.FileName;
        sTempFile := SaveFileFromDataBase ('test','somefile', Form1.TableGrid1.dbItemID);
        CopyFile(sTempFile, sFileName);
        DeleteFile(sTempFile);
    end;
    SaveDialog.Free;
end;
Dmitry.

Re: Question about DBFiles

Dear Dmitry,
.
Works perfect.
Thank you for your help.
.
I wish, other software vendors would work so effective and helpfull as you.