Upload file to DB and download

  • Last update:  2021-05-19
  • I. Overview

    1. Application scenarios

    Hoping that users can directly save small files in the database, and download these files in the report.


    2. Realization idea

    Upload: Use the "File Widget" to upload the file, set the Data Entry Attributes, and save it to the database field in a binary stream (the field type must be able to store binary data)

    The types of fields that can be stored in each database are different. The following lists the field types that commonly used databases store binary data:

    DatabaseField type used to save binary data  
      Sql Sever image
      Oracle blob
      MySQL blob
      Access OLE object

    Download: Drag the binary data column into the cell, and set the "Other> Display Content" of the Cell Attributes to display the binary content with the download link, and then the download can be realized.

    Note: This document is suitable for uploading and downloading small files. If the file is too large, it will take up too much space of database table. It is recommended to use the upload and download file plugin.

    II. Example

    Below we illustrate the implementation process by uploading a jpg file to the MySQL database and downloading it as an example.

    Note: The FRDemo database that comes with FanRuan is a Sqlite database, and it does not support downloading files.


    1. Data preparation

    1) Prepare a jpg file, such as 1.jpg;

    2) A database table test is created in the database, which contains fields (filename[varchar], file[Blob]). as shown in figure below:

    1.png

    3) After designing the table, establish a connection between the designer and the database. For details, refer to JDBC connection to database.


    2. Upload

    1) Create a template

    Insert the formula filename(B2) into cell A2. Add "File Widget" to cell B2.

    2.png

    If there is a need to insert a row, you need to select cell A2 and set "Cell Attributes> Other> Insert Row Policy" to the Original, otherwise the formula for the inserted row will become invalid.

    3.png

    2) Set Data Entry Attributes

    Add built-in SQL to bind columns and values in the Data Entry Attributes, as shown in the following figure:

    4.png

    3) Upload and submit

    Save the template and click Data Entry Preview. Use the widget in cell B2 and select a local file to upload, as shown in the figure below:

    5.png

    After uploading successfully, click Submit to see the data in the database. As shown in the figure below:

    6.png


    3. Download

    Create a template, add a dataset ds1, the SQL statement is select * from test

    7.png

    Drag the field into the cell, and set the "Other> Display Content" of the cell where the file field is located to "Display the binary content using download link", and set the "File Name for Download" as shown in the figure below:

    8.png

    Save the template and click Data Entry Preview, you will see the file field will be displayed in the form of a hyperlink, click on the hyperlink to download.

    9.png

    III.Completed templates

    Refer to the completed templates:

    %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\DataEntry\DataEntryApplication\Upload_to_database_and_download.cpt

    %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\DataEntry\DataEntryApplication\download.cpt

    Click to download:

    Upload_to_database_and_download.cpt

    download.cpt


    Attachment List


    Theme: Data Entry
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy