This discussion is archived
10 Replies Latest reply: Mar 1, 2013 8:09 AM by bondurs RSS

Issue with Downloading BLOB Documents in Apex 4.0

bondurs Newbie
Currently Being Moderated
Greetings:

I have created a custom table in the DB to handle any documents that our users want to upload for storage. The uploading and downloading of files is all done thru an APEX 4.0 application that I have built. The uploading portion of the app works great, it's just the downloading of these files that is causing problems for me.

I have created a link on the page that allows the user to download the document. I used Denis Kubicek's example to extract the blob out of the table and send it through the browser to download. It actually does download the file, but the file renders in the browser, rather than asking if the user wants to "Open" or "Save" the document to their local drives. This happens in both IE (V9.0.8) and Firefox (V18.0).

BTW, I have "Use software rendering instead of GPU rendering" turned off in IE.

Below is the code I'm using to extract the blob. What am I missing here that would cause the file to render directly in the browser, rather than prompting the user if they want to "Open" or "Save" the document?

Thanks so much,
Stan


Here is the link that calls the code to download the docs: https://xxxxxxxx/pls/apex/f?p=900:0:4003915419476346:DOWNLOADDOCUMENT:::F900_DOCUMENT_ID:1186978

- DOWNLOADDOCUMENT is an application process that looks like this:
begin

if :F900_DOCUMENT_ID is not null then
DownloadDocumentDB(:F900_DOCUMENT_ID);
end if;

end;

-- DOWNLOADDOCUMENT calls this:
create or replace procedure DownloadDocumentDB(inDocID IN NUMBER) is

cursor x1 is
select *
from x_doc_table
where cntrc_eval_doc_id = inDocID;

holdRec cntrc_eval_doc%rowtype := null;
holdLength number := null;

begin

if inDocID is not null then

open x1;
fetch x1 into holdRec;
close x1;

holdLength := dbms_lob.getlength(holdRec.cntrc_eval_doc); -- holdRec.cntrc_eval_doc is the BLOB column

-- use an NVL around the mime type and
-- if it is a null set it to application/octect
-- application/octect may launch a download window from windows
OWA_UTIL.mime_header (NVL (holdRec.cntrc_eval_doc_mime_typ_txt, 'application/octet'), FALSE); -- holdRec.cntrc_eval_doc_mime_typ_txt stores the MIME type

-- set the size so the browser knows how much to download
HTP.p ('Content-length: ' || holdLength);

-- the filename will be used by the browser if the users does a save as
HTP.p ( 'Content-Disposition: attachment; filename="'
|| REPLACE (REPLACE (SUBSTR (holdRec.cntrc_eval_doc_file_nme_txt, -- holdRec.cntrc_eval_doc_file_nme_txt stores the file name
INSTR (holdRec.cntrc_eval_doc_file_nme_txt, '/') + 1
),
CHR (10),
NULL
),
CHR (13),
NULL
)
|| '" '
);

-- close the headers
OWA_UTIL.http_header_close;

-- download the BLOB
WPG_DOCLOAD.download_file (p_blob => holdRec.cntrc_eval_doc);

end if;
end;

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points