“Download Blob” using Interactive Grid

后端 未结 1 1596
一向
一向 2021-01-25 15:58

What is equivalent to the Interactive Report \"Download Blob\" for Interactive Grids?

Currently I am using an Interactive Report as my workaround but would like to use I

相关标签:
1条回答
  • 2021-01-25 16:41

    Here are some steps that show you how it's done in APEX 19.2. Feel free to adjust as needed for other versions of APEX and as per your business requirements.

    1. Create a table to store BLOB files and add a file as an example.

      create table files (
          id            number generated by default as identity,
          mime_type     varchar2(255),
          name          varchar2(255),
          content       blob,
          constraint files_pk primary key (id)
      )
      /
      
      insert into files (
        mime_type,
        name,
        content
      ) values (
        'text/plain',
        'test.txt',
        hextoraw('48656c6c6f20576f726c6421')
      );
      
      commit;
      
    2. Create a new Interactive Grid page on the table using this query:

      select id,
        mime_type,
        name,
        dbms_lob.getlength(content) file_size
      from files
      
    3. Create a new Blank Page in your application. Set Page Number to 9000 and set Name to Download File.

    4. In the left-hand column of the Page Designer, right-click Content Body (under Regions) and select Create Region. Right-click the new region and select Create Page Item. Set the Name of the new item to P9000_FILE_ID and set the Type to Hidden. Note that neither the region or its item will ever be displayed.

    5. In the left-hand column of the Page Designer, open the Pre-Rendering section, right-click Before Header, then select Create Process. Set the Name of the process to Download File and enter the following code for the PL/SQL Code:

      declare
      
        l_files_rec files%rowtype;
      
      begin
      
        select *
        into l_files_rec
        from files
        where id = :P9000_FILE_ID;
      
        owa_util.mime_header(l_files_rec.mime_type, false);
        htp.p('Content-Length: ' || dbms_lob.getlength(l_files_rec.content));
        htp.p('Content-Disposition: attachment; filename="' || l_files_rec.name || '"');
        owa_util.http_header_close;
      
        wpg_docload.download_file(l_files_rec.content);
      
        apex_application.stop_apex_engine;
      
      end;
      

      This PL/SQL code is what gets the file from the database and streams it to the browser. You may want to modify this code, for example, to ensure a user should have access to the file they are trying to download. Also, consider application and page level security.

    6. In the Page Designer, return to the Interactive Grid page. Right-click Columns under the Interactive Grid region and select Create Column. Set Column Name to Download, Type to Link, and (under Source) set Type to None. Click the No Link Defined button for Target to open the link settings. Set Page to 9000, use the popup to select P9000_FILE_ID under the Name column, use the popup to select ID under the Value column (in the same row), then click the OK button. Finally, set Link Text (under Target) to download.

    To test, run the page and click the download link. The browser should download the file and when you open it the contents should be: Hello World!

    0 讨论(0)
提交回复
热议问题