In Finereport, you will be expected to directly save TXT, Excel and other files in the database to be backed up, and you want to make a report through Finereport to download these files down the situation.
Upload: Upload a file using a file control, save in a binary stream to a database field (the field type must be used to hold binary data);
Download: Drag binary data directly into the cell, set other properties of the cell > Display binary content with a download link to download the file.
The following is an example of the implementation process by uploading a TXT file to the SQL Server database and downloading it. The SQLite database supports uploads only and does not support downloads.
Prerequisite Preparation
Prepare a TXT file, create a database table file, contain fields (filename[text], File[blob objects])
Database different types of fields that can save files are different, and the following is a list of the field types used to store binary data for a common database:
650) this.width=650; "src=" http://img.blog.csdn.net/20170105093603674 "style=" border:0px none; "/>
Uploading files to a database
After the premise is ready, you can make a fill template, upload files to the database, the file is stored in a binary data stream in the database field, the template design interface is as follows, and follow the instructions on the diagram to set the report properties:
650) this.width=650; "src=" http://img.blog.csdn.net/20170105093613496 "style=" border:0px none; "/>
If it is a single file upload, it can be strictly controlled, check only support single file upload, you can also set the type of files allowed to upload, if it is multi-file upload, there is no need to tick only support single file upload this tick option.
Save the template, make a preview, upload the file and submit it, and the file will be saved to the database in binary data:
Mouse to the file control cell, that is, B2, click the Edit button in the upper right corner to enter the editing state, click the Upload button to upload files, such as:
650) this.width=650; "src=" http://img.blog.csdn.net/20170105093628378 "style=" border:0px none; "/>
650) this.width=650; "src=" http://img.blog.csdn.net/20170105093636315 "style=" border:0px none; "/>
650) this.width=650; "src=" http://img.blog.csdn.net/20170105093644184 "style=" border:0px none; "/>
After the commit succeeds, you can see the data in the database.
Download
Reopen the template, add the database query Ds1,sql statement for select *from file, query the saved data; Drag the field into the cell and set the other properties of the cell that contains the file field > display the binary content with the download link and set the downloaded file name:
650) this.width=650; "src=" http://img.blog.csdn.net/20170105093656816 "title=" click to view original size picture "class=" Magplus "width=" "Height=" 231 "style=" border:0px none; "/>
Save the template again, fill in the preview, you can click to download:
650) this.width=650; "src=" http://img.blog.csdn.net/20170105093704638 "style=" border:0px none; "/>
Upload files to database and download