Forum Stats

  • 3,757,187 Users
  • 2,251,208 Discussions
  • 7,869,755 Comments

Discussions

Download blob from function instead table field

pjsiong-JavaNet
pjsiong-JavaNet Member Posts: 398 Green Ribbon
edited Jun 23, 2011 11:45PM in APEX Discussions
Hi,
Is that possible to download blob field content which are return by a function?
I can only download blob if the blob is in table column..

Thanks

Vincent

Best Answer

  • Srecio-Oracle
    Srecio-Oracle Member Posts: 147 Employee
    Accepted Answer
    Hi Vincent,

    I think that you can download blob content returned by a function without any problem. In the example below, the function get_blob returns a BLOB, you will have to specify the mime type and filename, and the BLOB length is obtained using the function DBMS_LOB.GETLENGTH. Finally, a call to the wpg_docload.download_file procedure is made. To call the download_file procedure you can do it through the URL or through a page with a "Branch To PL/SQL Procedure" in the "Before Header" point. More info about this kind of procedure here.
    create or replace PROCEDURE  "DOWNLOAD_FILE"
    (
        inID NUMBER
    )
    AS
        vMIME VARCHAR2(48);
        vLENGTH NUMBER;
        vFILENAME VARCHAR2(2000);
        vBLOB BLOB;
    BEGIN
        vMIME := 'application/octet-stream';
        vFILENAME := 'Test.sql';
        vBLOB := get_blob(inID);
        vLENGTH := DBMS_LOB.GETLENGTH(vBLOB);
        owa_util.mime_header(nvl(vMIME, 'application/octet'), FALSE);
        htp.p('Content-length: ' || vLENGTH);
        htp.p('Content-Disposition: attachment; filename="' || SUBSTR(vFILENAME, INSTR(vFILENAME, '/') + 1) || '"');
        owa_util.http_header_close;
        wpg_docload.download_file(vBLOB);
    END;
    Regards,

    Sergio

Answers

  • Srecio-Oracle
    Srecio-Oracle Member Posts: 147 Employee
    Accepted Answer
    Hi Vincent,

    I think that you can download blob content returned by a function without any problem. In the example below, the function get_blob returns a BLOB, you will have to specify the mime type and filename, and the BLOB length is obtained using the function DBMS_LOB.GETLENGTH. Finally, a call to the wpg_docload.download_file procedure is made. To call the download_file procedure you can do it through the URL or through a page with a "Branch To PL/SQL Procedure" in the "Before Header" point. More info about this kind of procedure here.
    create or replace PROCEDURE  "DOWNLOAD_FILE"
    (
        inID NUMBER
    )
    AS
        vMIME VARCHAR2(48);
        vLENGTH NUMBER;
        vFILENAME VARCHAR2(2000);
        vBLOB BLOB;
    BEGIN
        vMIME := 'application/octet-stream';
        vFILENAME := 'Test.sql';
        vBLOB := get_blob(inID);
        vLENGTH := DBMS_LOB.GETLENGTH(vBLOB);
        owa_util.mime_header(nvl(vMIME, 'application/octet'), FALSE);
        htp.p('Content-length: ' || vLENGTH);
        htp.p('Content-Disposition: attachment; filename="' || SUBSTR(vFILENAME, INSTR(vFILENAME, '/') + 1) || '"');
        owa_util.http_header_close;
        wpg_docload.download_file(vBLOB);
    END;
    Regards,

    Sergio
  • pjsiong-JavaNet
    pjsiong-JavaNet Member Posts: 398 Green Ribbon
    Thanks Sergio, it's work..
This discussion has been closed.