Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Upload files to the database and download

2025-01-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

In FineReport, there will be situations where you want to directly save the entire txt, excel and other files in the database for backup, and you want to make reports through FineReport to download these files.

Upload: use the file control to upload the file and save it in a binary stream to the database field (the field type must be used to save binary data)

Download: directly drag the binary data into the cell, set other properties of the cell > use the download link to display the binary content, you can download the file.

The implementation process is illustrated by uploading a txt file to the sql server database and downloading it as an example. Sqlite database only supports uploading, not downloading.

Prerequisite preparation

Prepare a txt file, and create a database table file in the database that contains fields (filename [text], file [Blob object])

The types of fields in which files can be saved vary from database to database. The following is a list of field types that commonly used databases hold binary data:

Upload files to the database

Template making

When the premise is ready, you can make a report template, upload the file to the database, and save the file in the database field as a binary data stream. The template design interface is as follows, and set the report attributes as shown in the figure:

If it is a single file upload, it can be strictly controlled. Check the box to support only single file upload, and you can also set the type of files that are allowed to be uploaded. If it is a multi-file upload, you do not need to check the option to support only single file upload.

Upload and submit

Save the template, fill in the preview, upload the file and submit it, and the file will be saved to the database as binary data:

Move the mouse to the cell where the file control is located, that is, B2, click the edit button in the upper right corner to enter the editing state, and click the upload button to upload the file, as shown below:

After the submission is successful, you can see the data in the database.

download

Reopen the template, add the database query ds1,SQL statement as select * from file, query the saved data, drag the field into the cell, and set the other properties of the cell where the file field resides. > display the binary content with the download link, and set the downloaded file name:

Save the template again, fill in the preview, and click to download:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 239

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report