Thomas Carlton
Thomas Carlton

Reputation: 5958

Apex - How to download pdf file instead of showing it in the browser?

I'm running Apex 19.2.

I have a pdf stored as blob file in a table. I'm trying to download the blob in a page process.

The process works fine however, the file doesn't download but gets displayed in the browser instead.

Can anyone help please ? I need the file to download and not show in the browser...

Here is my code :

        File Blob; -- Blob content is set somewhere else...
        sys.HTP.init;
        sys.OWA_UTIL.mime_header(MimeType, FALSE);
        sys.HTP.p('Content-Length: ' || DBMS_LOB.getlength(File));
        sys.HTP.p('Content-Disposition: filename="report.pdf"');
        sys.OWA_UTIL.http_header_close;

        sys.WPG_DOCLOAD.download_file(file);
        apex_application.stop_apex_engine;  

Thanks, Cheers,

Upvotes: 1

Views: 4269

Answers (2)

Dan McGhan
Dan McGhan

Reputation: 4659

Change this line:

sys.HTP.p('Content-Disposition: filename="report.pdf"');

To this:

sys.HTP.p('Content-Disposition: attachment; filename="report.pdf"');

Upvotes: 1

Related Questions