首页 归档 关于 learn love 工具

Oracle apex 上传图片

apex文件上传流程如下:

  1. 创建类型为 file browser 的页面项
  2. 提交页面后,apex自动将文件上传到临时表 APEX_APPLICATION_TEMP_FILES 中
  3. 将临时表APEX_APPLICATION_TEMP_FILES 中的数据报存到自己的正式表中

创建自定义表

创建一个自定义的表,用于保存上传的文件

create table bhsc_files 
as select * 
from APEX_APPLICATION_TEMP_FILES
 where 1=2;

创建页面项(page item)

  1. 创建页面项,type为 file browser
page item type
  1. Storage Type 设为 Table APEX_APPLICATION_TEMP_FILES
storage type
  1. Purge File at 设为 End of Request
purge file

创建页面Processing

下一步就是需要将APEX_APPLICATION_TEMP_FILES表中的数据保存起来,创建一个processing,语句如下

begin
insert into bhsc_files  select * from APEX_APPLICATION_TEMP_FILES;
end;
保存文件

创建提交页面的button

最后创建一个提交页面的按钮,提交页面后就保存到数据库了。

附件下载

  1. 跳转到共享组件(shared components) --> Application Processes
创建应用过程
  1. 创建一个名为 APP_FILE_ID的Application item , scope为 Application,Session State Protection为 Unrestricted

  2. 创建一个名为 APP_DOWNLOAD_FILE,Process Point为 Ajax Callback的过程,代码如下:

begin
    for c1 in (select * from bhsc_files  
                where id = :APP_FILE_ID) loop
        sys.htp.init;
        sys.owa_util.mime_header( c1.mime_type, FALSE );
        sys.htp.p('Content-length: ' || sys.dbms_lob.getlength( c1.blob_content));
        sys.htp.p('Content-Disposition: attachment; filename="' || c1.filename || '"' );
        sys.htp.p('Cache-Control: max-age=3600');  -- tell the browser to cache for one hour, adjust as necessary
        sys.owa_util.http_header_close;
        sys.wpg_docload.download_file( c1.blob_content );
     
        apex_application.stop_apex_engine;
    end loop;
end;
创建Application Processes
  1. 在页面上创建一个区域(region),类型为 classic report,语句如下:
select id,name,filename,null download_link from bhsc_files  
  1. 设置download_link字段的类型为 link,target为 page in this application,page为 0,set item设置 APP_FILE_ID#ID#,advanced那里设置request值为 APPLICATION_PROCESS=APP_DOWNLOAD_FILE 具体信息如下
下载

附件删除

附件删除的步骤与附件下载相同,一样是创建一个名为 APP_DELETE_FILE的Application Processes,代码如下

begin
    for c1 in (select * from bhsc_files
                where id = :APP_FILE_ID) loop
        delete from bhsc_files where  id = :APP_FILE_ID;
    end loop;
end;

在下载报表那里加多一个字段,字段设置为link,request值为 APPLICATION_PROCESS=APP_DELETE_FILE