我有点问题。我试图从APEX应用程序下载文件。文件正确下载,但浏览器无法将文件识别为PDF。下面的代码完美无缺,但缺乏对文件类型的识别。
create or replace PROCEDURE DOWNLOAD_LIST
(p_id_list in VARCHAR2) AS
v_mime VARCHAR2(2000);
v_length NUMBER;
v_file_name VARCHAR2(2000);
Lob_loc BLOB;
BEGIN
SELECT MIME_TYPE, BLOB_CONTENT, CODI ,DBMS_LOB.GETLENGTH(blob_content)
INTO v_mime,lob_loc,v_file_name,v_length
FROM table
WHERE ID_LIST = p_id_list;
-- set up HTTP header
-- 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
-- I've tried to put either pdf or octet. The database file has 'application/pdf' as mime_type
owa_util.mime_header( nvl(v_mime,'application/pdf'), FALSE );
-- set the size so the browser knows how much to download
htp.p('Content-length: ' || v_length);
-- the filename will be used by the browser if the users does a save as
--htp.p('Content-Disposition: attatchment; filename="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
htp.p('Content-Disposition: attatchment; filename="'||v_file_name||'.pdf'||'"');
-- close the headers
owa_util.http_header_close;
-- download the BLOB
wpg_docload.download_file( Lob_loc );
end DOWNLOAD_LIST;
任何帮助?
答案 0 :(得分:0)
不是那么简单;要求您采取一些额外步骤,如Creating PDF Reports with Oracle Application Express 5.0 and Oracle REST Data Services中所述。看一下,该教程需要20分钟才能完成。我希望它会有所帮助。
答案 1 :(得分:0)
我认为您的内容长度存在轻微问题:
这是我在制作中的代码,它确实使用浏览器内置的查看器正确显示.pdf文件:
PROCEDURE PR_SHOW_REPORT(io_blReport IN OUT BLOB,
i_vcContentDisposition IN VARCHAR2 DEFAULT 'inline',
i_vcFilename IN VARCHAR2 DEFAULT 'reportresult.pdf') IS
l_mime VARCHAR2 (255);
l_length NUMBER;
l_file_name VARCHAR2 (2000);
lob_loc BLOB;
BEGIN
OWA_UTIL.mime_header ('application/pdf', FALSE);
HTP.p ('Content-Length: ' || DBMS_LOB.GETLENGTH(io_blReport));
HTP.p ('Content-Disposition: ' || i_vcContentDisposition ||'; filename="' || i_vcFilename || '"');
OWA_UTIL.http_header_close;
WPG_DOCLOAD.download_file(io_blReport);
END;