Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Download a PDF as BLOB from a table with APEX 4.2? (knowing there is a lot of discussion out there)

Norbert MeJun 15 2017 — edited Jun 16 2017

Hi,

as many many others I am trying to download a PDF from a table with APEX 4.2.

So I wrote (rather c&p)) an On-Demand Application Process :

declare

    v_pdf    BLOB;

begin

apex_debug.info('start in AJAX process GET_EXAMPLE_DOWNLOAD');

    select fuppdf into v_pdf

                 from v_pdfdata

                where fupprgtransid = '2c908fb54b9cebf3014ba1b3bc3152cd';  -- hardcoded for the example

        --

        sys.htp.init;

        sys.owa_util.mime_header( 'application/pdf', FALSE );

        sys.htp.p('Content-length: ' || sys.dbms_lob.getlength( v_pdf));

        sys.htp.p('Content-Disposition: attachment;');

        sys.htp.p('filename="' || '2c908fb54b9cebf3014ba1b3bc3152cd' || '.pdf"' );

        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( v_pdf );

        -- I am not sure about this

      --apex_application.stop_apex_engine;

        --  throws an exception: ORA-20876: Stop APEX Engine, ORA-06512: in "APEX_040200.WWV_FLOW", Line 3255 ORA-06512: in Line 20

apex_debug.info('end in AJAX process GET_EXAMPLE_DOWNLOAD');

    EXCEPTION when others then

apex_debug.error('exception in AJAX process: %s, %s', sqlerrm, DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);

        raise;    

end;

and used a JavaScript Dynamic Action to call it with apex.server.process.

The same code as On-Demand Page Process.

And yet another On-Demand Page Process to call the On-Demand Application Process.

Then I created buttons to call them all:

apex.server.process runs fine as I see by a dummy session parameter that is set differently for each version.

The processes run without exception as I see from the APEX Debug Log.

But the results leave me helpless:

  • Application Process gives an Error Alert box:

     Error: error- Not Found

  • Page Process gives an Error Alert box:

     Error: error- Not Found

  • Page Process that calls the Application Process:

     Shows Nothing at all

I also tried to use a direct call of an URL in different ways:

f?p=&APP_ID.:8:&SESSION.:APPLICATION_PROCESS=GET_EXAMPLE_DOWNLOAD:&DEBUG.::G_PARAM:HREF::

with Session State Protection of G_PARAM = Unrestricted (this gives me pain)

The results are even more confusing:

The URL comes out right but the page shows: Not found: The requested URL /pls/apex/f was not found.

(ok, I admit that sometimes a totally wrong sessionid was shown in the URL field, maybe because of running in the development environment)

and &APP_ID.:0:... does not work either

Same results for Firefox 52 and IE11 on Windows and Firefox on Linux.

OBTW: Firefox and IE11 on Windows are the target combinations.

What am I missing?

Of course, any help is appreciated

Norbert

I also want to do this with an PNG image but I'm sure I can handle this the same way.

This post has been answered by Pavel_p on Jun 15 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 14 2017
Added on Jun 15 2017
2 comments
2,280 views