【问题标题】:"Download Blob" using Interactive Grid使用交互式网格“下载 Blob”
【发布时间】:2019-01-19 17:32:39
【问题描述】:

什么相当于交互式网格的交互式报表“下载 Blob”?

目前我使用交互式报表作为我的解决方法,但我想使用交互式网格但是没有下载 Blob 列类型,我不想破解 select 子句中的 URL。

【问题讨论】:

  • 您使用的是 APEX 5.1 还是 18.1?
  • 添加网址不是黑客行为。在 Apex 中这被认为是很正常的

标签: blob oracle-apex


【解决方案1】:

这里有一些步骤向您展示了它是如何在 APEX 19.2 中完成的。随意根据其他版本的 APEX 的需要和您的业务需求进行调整。

  1. 创建一个表来存储BLOB文件并添加一个文件作为例子。

    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. 使用此查询在表上创建一个新的交互式网格页面:

    select id,
      mime_type,
      name,
      dbms_lob.getlength(content) file_size
    from files
    
  3. 在您的应用程序中创建一个新的空白页。将 Page Number 设置为 9000,并将 Name 设置为 Download File。

  4. 在页面设计器的左侧列中,右键单击 Content Body(在 Regions 下)并选择 Create Region。右键单击新区域并选择创建页面项目。将新项目的 Name 设置为 P9000_FILE_ID 并将 Type 设置为 Hidden。请注意,该区域或其项目都不会显示。

  5. 在页面设计器的左侧栏中,打开Pre-Rendering部分,右键单击Before Header,然后选择Create Process强>。将进程的名称设置为 Download File 并为 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;
    

    此 PL/SQL 代码用于从数据库中获取文件并将其流式传输到浏览器。例如,您可能想要修改此代码,以确保用户应该有权访问他们尝试下载的文件。此外,还要考虑应用程序和页面级别的安全性。

  6. 在页面设计器中,返回交互式网格页面。右键单击 Interactive Grid 区域下的 Columns,然后选择 Create Column。将 Column Name 设置为 Download,将 Type 设置为 Link,并且(在 Source 下)将 Type 设置为 None。点击TargetNo Link Defined按钮打开链接设置。设置Page为9000,使用弹窗选择Name栏下的P9000_FILE_ID,使用弹窗选择Value栏下的ID(在同一行),然后单击确定按钮。最后,设置Link Text(在Target下)下载。

要进行测试,请运行该页面并单击下载链接。浏览器应该会下载文件,当你打开它时,内容应该是:Hello World!

【讨论】:

    猜你喜欢
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    • 2020-02-22
    • 2023-04-07
    • 2019-01-26
    相关资源
    最近更新 更多