Download/Open BLOB as PDF document
531473Mar 4 2009 — edited May 16 2013I've inherited some common code that uses OWA_UTIL and WPG_DOCLOAD packages to store documents as BLOB and retrieve them from a website. I've been asked to see if it's possible to download/open those documents as PDFs regardless of how they were initially uploaded and stored (.doc, .docx, .txt, .html, .rtf, etc). Is this possible? I don't see how but I could be missing something. If the documents were themselves physically stored on disk, then I would run it through some 3rd-party PDF converter. But, since the document content is stored in a BLOB in a db table, it just doesn't see possible. Any assistance is very much appreciated. Thanks.
Here's the code that you may have seen on-line that is being used here:
-- ----------------------------------------------------------------------------
PROCEDURE download (pfile IN VARCHAR2) AS
-- ----------------------------------------------------------------------------
l_blob_content fis_document.blob_content%TYPE;
l_mime_type fis_document.mime_type%TYPE;
BEGIN
SELECT blob_content,
mime_type
INTO l_blob_content,
l_mime_type
FROM fis_document
WHERE name = pfile;
OWA_UTIL.mime_header(l_mime_type, FALSE);
HTP.p('Content-Length: ' || DBMS_LOB.getlength(l_blob_content));
OWA_UTIL.http_header_close;
WPG_DOCLOAD.download_file(l_blob_content);
EXCEPTION
WHEN OTHERS THEN
HTP.htmlopen;
HTP.headopen;
HTP.title('File Download');
HTP.headclose;
HTP.bodyopen;
HTP.header(3, 'Download Status');
HTP.print(SQLERRM);
HTP.bodyclose;
HTP.htmlclose;
END;
It uses the common table to store the document information and BLOB contents:
CREATE TABLE documents (
name VARCHAR2(256) UNIQUE NOT NULL,
mime_type VARCHAR2(128),
doc_size NUMBER,
dad_charset VARCHAR2(128),
last_updated DATE,
content_type VARCHAR2(128),
blob_content BLOB
)