Home » SQL & PL/SQL » SQL & PL/SQL » Send file to client (9g)
icon5.gif  Send file to client [message #606903] Thu, 30 January 2014 10:20 Go to next message
Lalilulelo
Messages: 3
Registered: January 2014
Junior Member
Hi all. Sorry for my english. Can u help me with owa package? I need access my package thru url and browser will begin download file which was created in pl/sql code. I need somethink like content-type: attachment i gues.
Re: Send file to client [message #606916 is a reply to message #606903] Thu, 30 January 2014 12:25 Go to previous messageGo to next message
Lalilulelo
Messages: 3
Registered: January 2014
Junior Member
in oralce i can create package like this.

create or replace procedure hello AS
BEGIN
htp.htmlopen; -- generates <HTML>
htp.headopen; -- generates <HEAD>
htp.title('Hello'); -- generates <TITLE>Hello</TITLE>
htp.headclose; -- generates </HEAD>
htp.bodyopen; -- generates <BODY>
htp.header(1, 'Hello'); -- generates <H1>Hello</H1>
htp.bodyclose; -- generates </BODY>
htp.htmlclose; -- generates </HTML>
END;

then i can access it through URL and get a web page.
but i want server send me a file. i know that i need to use 'content-type' in http header.

PHP ANALOG:
<?php
$filename="download.txt";
header("Content-disposition: attachment;filename=$filename");
readfile($filename);
?>
http://crossfire.real-time.com/editors/install/images/04_windows-download2.gif


The only difirance is that i want crate text file myselt in code.
Re: Send file to client [message #606994 is a reply to message #606903] Fri, 31 January 2014 15:27 Go to previous message
Lalilulelo
Messages: 3
Registered: January 2014
Junior Member
I found it!

PROCEDURE download (file IN VARCHAR2) AS
l_blob_content documents.blob_content%TYPE;
l_mime_type documents.mime_type%TYPE;
BEGIN
SELECT blob_content,
mime_type
INTO l_blob_content,
l_mime_type
FROM documents
WHERE name = file;

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 no_data_found THEN
HTP.p('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">');
HTP.htmlopen;
HTP.headopen;
HTP.title('404 Not Found');
HTP.headclose;
HTP.bodyopen;
HTP.header(1, 'Not Found');
HTP.print('<p>The requested URL /'||file||' was not found on this server.</p>');
HTP.bodyclose;
HTP.htmlclose;
Previous Topic: Tablename as input parameter
Next Topic: Formatting html file for an explain plan
Goto Forum:
  


Current Time: Fri Apr 26 22:55:03 CDT 2024