Display BLOB contents to client

I want to display the blob contents in the clients window and give him the option either to open or save the contents. I am able to read the contents from Oracle Blob Field and stored the contents in the ByteArrayOutputStream object but I am not able to open the contents for the client. I am using the following code
Blob blob = resultSet.getBlob(1);
int length = (int)blob.length();
byte [] b = blob.getBytes(1, length );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(b,0,length);
response.setHeader("Content-Disposition","attachment; filename="+baos );
Please help me

I am able to see the blob contents in the client window but the file does not show as attachment which is my main purpose-- to give the user the option either to open the file or to save the file on his machine. I am also setting the setHeader as attachment , but nothing happens....and sometimes it shows a dialog box to open my jsp file itself rather than the desired file... sending you the code ..please help
File file1 = new File("c:\\Test.java");
byte[] buffer = new byte[(int)file1.length()];
BufferedInputStream is = new BufferedInputStream(new FileInputStream(file1));
is.read(buffer, 0, (int)file1.length());
is.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(buffer, 0, (int)file1.length());
System.out.println(baos.toString());
byte[] pass = baos.toByteArray();
response.setHeader("Content-Desposition", "attachment;filename=untitled.java");
response.setContentType("application/octet-stream");
//Send content to Browser
ServletOutputStream servletOut = response.getOutputStream();
servletOut.write(pass);
servletOut.close();

Similar Messages

  • Display blob content as pdf file

    Dear Expert,
    Currently i'm using oracle apex 3.0.1.
    I'm having a problem on displaying blob content (from database table) as pdf file on oracle application express but i'm able to save to download the pdf.
    Below is the procedure that i used to display blob content,
    PROCEDURE lf_html_pdf (pv_image IN VARCHAR2, pv_index IN NUMBER) is
    l_mime VARCHAR2 (255);
    l_length NUMBER;
    l_file_name VARCHAR2 (2000);
    lob_loc BLOB;
    BEGIN
    begin
    selecT OI_BLOB,DBMS_LOB.getlength (OI_BLOB)
    into lob_loc,l_length
    from ord_img
    where oi_tno= pv_image
    and oi_ti='PDF'
    and oi_idx=pv_index;
    exception
    when others then
    null;
    end;
    OWA_UTIL.mime_header (NVL (l_mime, 'application/pdf'), FALSE);
    HTP.p ('Content-length: ' || l_length);
    OWA_UTIL.http_header_close;
    WPG_DOCLOAD.download_file (lob_loc);
    END lf_html_pdf;
    I get the error message as below when i execute the procedure above;
    Error report:
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at "SYS.OWA_UTIL", line 356
    ORA-06512: at "SYS.OWA_UTIL", line 415
    ORA-06512: at "HCLABPRO.PKG_PDF", line 220
    ORA-06512: at line 2
    *06502. 00000 - "PL/SQL: numeric or value error%s"*
    I'm appreciated if expert can have me on the problem above?
    Thanks
    From junior

    *Always post code wrapped in <a href=http://wikis.sun.com/display/Forums/Forums+FAQ#ForumsFAQ-Arethereanyusefulformattingoptionsnotshownonthesidebar?"><tt>\...\</tt> tags</a>:*
      PROCEDURE lf_html_pdf (pv_image IN VARCHAR2, pv_index IN NUMBER) is
         l_mime        VARCHAR2 (255);
         l_length      NUMBER;
         l_file_name   VARCHAR2 (2000);
         lob_loc       BLOB;
      BEGIN
          begin
            selecT OI_BLOB,DBMS_LOB.getlength (OI_BLOB)
            into lob_loc,l_length
            from ord_img
            where  oi_tno= pv_image
              and oi_ti='PDF'
              and oi_idx=pv_index;
          exception
                when others then
                null;
            end;
         OWA_UTIL.mime_header (NVL (l_mime, 'application/pdf'), FALSE);
         HTP.p ('Content-length: ' || l_length);
         OWA_UTIL.http_header_close;
         WPG_DOCLOAD.download_file (lob_loc);
      END lf_html_pdf; Start by getting rid of:
          exception
                when others then
                null;and never using it anywhere ever again.
    If you're not actually going to use the <tt>l_mime</tt> and <tt>l_file_name</tt> variables then remove these as well. (Although I really think you should set a filename.)
    >
    Error report:
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at "SYS.OWA_UTIL", line 356
    ORA-06512: at "SYS.OWA_UTIL", line 415
    ORA-06512: at "HCLABPRO.PKG_PDF", line 220
    ORA-06512: at line 2
    06502. 00000 - "PL/SQL: numeric or value error%s"
    >
    The error stack indicates that the exception is being raised in <tt>HCLABPRO.PKG_PDF</tt>: what is <tt>HCLABPRO.PKG_PDF</tt>? Does this actually have anything to do with the procedure above?
    I get the error message as below when i execute the procedure above;How do you execute it?
    What happens when it's executed without the <tt>when others...</tt> built-in bug?

  • Send Blob Contents to Client machine as Attachment

    I am able to see the blob contents in the client window but the file does not show as attachment which is my main purpose-- to give the user the option either to open the file or to save the file on his machine. I am also setting the setHeader as attachment , but nothing happens....and sometimes it shows a dialog box to open my jsp file itself rather than the desired file... sending you the code ..please help
    File file1 = new File("c:\\Test.java");
    byte[] buffer = new byte[(int)file1.length()];
    BufferedInputStream is = new BufferedInputStream(new FileInputStream(file1));
    is.read(buffer, 0, (int)file1.length());
    is.close();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(buffer, 0, (int)file1.length());
    System.out.println(baos.toString());
    byte[] pass = baos.toByteArray();
    response.setHeader("Content-Desposition", "attachment;filename=untitled.java");
    response.setContentType("application/octet-stream");
    //Send content to Browser
    ServletOutputStream servletOut = response.getOutputStream();
    servletOut.write(pass);
    servletOut.close();

    It works,
    you have a type!
    response.setHeader("Content-Desposition", "attachment;filename=untitled.java");
    It should be "Content-Disposition" not "Content-Desposition"
    try it out.
    cheers

  • Display Blob content in HTML Region

    Hello,
    I'm trying to display the contents of an .htm file in an html region. I can get it to display as a link but I can't get it to display as an image. I have a page item that is display as text (do not save state). For the source value I use a PL/SQL function body. I use the following code to display the image,
    return '<img scr="#OWNER#.get_help_doc?p=U76.htm></img>';
    I get the broken link symbol.
    However, if I display it as a link as follows, it works:
    return '<a href="#OWNER#.get_help_doc?p=U76.htm'
    || '">Help</a>';
    How can I display the .htm file as an image? Thanks, Elizabeth

    I found my answer in message
    http://apex.oracle.com/pls/otn/f?p=11933:120:3919935161915118::NO:RP::.
    I used the <embed src=>
    Elizabeth

  • Display Blob content in Apex

    Hi folks
    I hope you can see HTML Expression code now.
    I have PDFs stored in BLOB columns along with FILE_ID column in the database.
    I want to display these to the APEX user on the page at runtime.
    I have created a SQL Query report page to display FILE_ID column.
    I am using HTML Expression property of the FILE_ID column to pull the image from the table using PROC_DISPLAY_DOCUMENT procedure.
    I typed folowing code int the HTML Expression text area of the FILE_ID column of the report page :
    [!-- img src="#OWNER#.proc_display_document?p_id=#file_id#" ]
    I am using following Procedure code:
    create or replace procedure "PROC_DISPLAY_DOCUMENT"(p_id number) **
    mimetype varchar2(48);
    n_length number;
    s_filename varchar2(400);
    lob_image blob;
    Begin
    select MIME_TYPE,dbms_lob.getlength(blob_content),file_name,blob_content
    into s_mime_type,n_length,s_filename,lob_image
    from tbl_upload_file
    where file_id = p_id;
    owa_util.mime_header(nvl(s_mime_type, 'application/octet' ),false);
    --set the size so the browser knows how much it will be downloading
    htp.p( 'content-length: '|| n_length );
    --The file name will be used by the browser if the users does a "save as"
    htp.p( 'content-Disposition: filename="' || s_filename ||'"');
    owa_util.http_header_close;
    --Download the BLOB
    wpg_docload.download_file( lob_image );
    exception
    WHEN NO_DATA_FOUND THEN
    RAISE_APPLICATION_ERROR(-202121,'Record matching screenfield filename not found, PROC_DISPLAY_DOCUMENT.');
    end;
    --This is very Important
    --grant execute on PROC_DISPLAY_DOCUMENT to public;
    This code does not work and Apex report does not display PDF image.
    Any help to troubleshoot this code will be appreciated.
    Thank you in advance.
    Jaya

    create or replace procedure "PROC_DISPLAY_DOCUMENT"(p_id number) **
    mimetype varchar2(48); ... Doesn't look correct to me. What are the ** for?
    Does the procedure compile?
    This code does not workHow did you come to this conclusion? Any error message you got?

  • How to display the content of a BLOB column in a ADF/BC pages ?

    How to display the content of a BLOB column in a ADF/BC pages ?
    There is some image in database table blog column. And we want to display image on the screeen.
    There is some example about upload and dowload blog columns.
    (steve not yet document example page etc...)
    But We want to display blog picture in a image component...
    is there any basic way to do it ?
    Thanks a lot...

    Ali,
    You could just download the sample app... but... here is the servlet code from the demo (look at it just for technique - you'll obviously have to change it for your needs)...
    John
    package oracle.fodemo.storefront.servlet;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import oracle.jbo.ApplicationModule;
    import oracle.jbo.Key;
    import oracle.jbo.Row;
    import oracle.jbo.ViewObject;
    import oracle.jbo.client.Configuration;
    import oracle.jbo.domain.BlobDomain;
    import oracle.jbo.domain.DBSequence;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.ViewObjectImpl;
    public class ImageServlet
      extends HttpServlet
      private static final String CONTENT_TYPE =
        "image/jpg; charset=windows-1252";
      public void init(ServletConfig config)
        throws ServletException
        super.init(config);
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
        throws ServletException, IOException
        response.setContentType(CONTENT_TYPE);
        response.setContentType(CONTENT_TYPE);
        String detailProductId = request.getParameter("detail");
        String thumbnailProductId = request.getParameter("thumbnail");
        boolean thumbnail = true;
        String productId = null;
        OutputStream os = response.getOutputStream();
        String amDef = "oracle.fodemo.storefront.store.service.StoreServiceAM";
        String config = "StoreServiceAMLocal";
        ApplicationModule am =
          Configuration.createRootApplicationModule(amDef, config);
        ViewObjectImpl vo =
          (ViewObjectImpl) am.findViewObject("ProductImages"); // get view object (the same as used in the table)
        if (detailProductId != null)
          productId = detailProductId;
          thumbnail = false;
        else
          productId = thumbnailProductId;
        vo.defineNamedWhereClauseParam("paramThumbnail", null, null);
        vo.defineNamedWhereClauseParam("paramProductId", null, null);
        vo.setWhereClause("DEFAULT_VIEW_FLAG = :paramThumbnail AND PRODUCT_ID = :paramProductId");
        vo.setNamedWhereClauseParam("paramThumbnail", (thumbnail? "Y": "N"));
        vo.setNamedWhereClauseParam("paramProductId", productId);
        vo.executeQuery();
        Row product = vo.first();
        BlobDomain image = (BlobDomain) product.getAttribute("Image");
        InputStream is = image.getInputStream();
        // copy blob to output
        byte[] buffer = new byte[10 * 1024];
        int nread;
        while ((nread = is.read(buffer)) != -1)
          os.write(buffer, 0, nread);
        os.close();
        vo.setWhereClause(null);
        vo.removeNamedWhereClauseParam("paramProductId");
        vo.removeNamedWhereClauseParam("paramThumbnail");
        Configuration.releaseRootApplicationModule(am, false);
    }

  • See BLOB contents on Oracle FORMS

    Is there anyway that I can see the BLOB object contents in Oracle Forms? For example, if I have a word document in BLOB, I should be able to open it in Oracle forms. I've already posted this today, but just for clarification, I'm reposting this with exact requirements. My client wishes to see data from a table and in that a BLOB object is one of the columns. For each row, there is a word document, which should also be displayed (or at least a link) on Form. If clicked on the link, the BLOB content, i.e., the word document should get opened. Please let me know if there is any way. Francois was trying to help me, I think this explanation makes it clear for him and also others. I don't have webutil library and my Forms version is 6.0.8.18.3. Please help me soon. I'm in an urgent realease this weekend and need this deliberately. It is not possible to upgrade to newer version for me.
    Thanks
    Sarma.

    In fact, I just had to do this today. It works as expected using an image item on the BLOB column. I am at 10.1.2.0.2, if that makes any difference. Are you positive you have data in the BLOB column? I noticed that after loading a table with image items, I used SQL Developer to look at the table to ensure there was data in the rows. After that, the images no longer appeared in the form. I had to reload the table, then all was well again.

  • Problem with displaying BLOB images on JSP page using a servlet

    hi. I have a big problem with displaying BLOB images using JSP. I have a servlet that connects to the oracle database, gets a BLOB image , reads it, and then displays it using a BinaryStream. The problem is , this works only when i directly call that servlet, that is http://localhost:8080/ImageServlet. It doesn't work when i try to use that servlet to display my image on my JSP page (my JSP page displays only a broken-image icon ) I tried several coding approaches with my servlet (used both Blob and BLOB objects), and they work just fine as long as i display images explicitly using only the servlet.
    Here's what i use : ORACLE 10g XE , Eclipse 3.1.2, Tomcat 5.5.16 , JDK 1.5
    here is one of my image servlet's working versions (the essential part of it) :
                   BLOB blob=null;
              rset=st.executeQuery("SELECT * FROM IMAGES WHERE ID=1");
              while (rset.next())
                   blob=((OracleResultSet)rset).getBLOB(2);
              response.reset();
              response.setContentType("image/jpeg");
              response.addHeader("Content-Disposition","filename=42.jpeg");
                    ServletOutputStream ostr=response.getOutputStream();
                   InputStream istr=blob.getBinaryStream(1L);
                    int size=blob.getBufferSize();
              int len=-1;
                    byte[] buff = new byte[size];
                         while ((len=istr.read( buff ))!=-1 ) {
                   ostr.write(buff,0,len);
             response.flushBuffer();
             ostr.close(); and my JSP page code :
    <img src="/ImageServlet" border="0"  > If you could just tell me what i'm doing wrong here , or if you could show me your own solutions to that problem , i would be very greatful ,cos i'm realy stuck here , and i'm rather pressed for time too. Hope someone can help.

    I turns out that it wasn't that big of a problem after all. All i had to do was to take the above code and place it into another JSP page instead of into a servlet like i did before. Then i just used that page as a source for my IMG tag in my first JSP. It works perfectly well. Why this doesn't work for servlets i still don't know, but it's not a problem form me anymore . Ofcourse if someone knows the answer , go ahead and write. I would still appriceatte it.
    here's the magic tag : <img src="ImageJSP.jsp" border="0"  > enjoy : )

  • Unable to display the Content of a data file from within another data file in Oracle webcenter portal.

    We have a Content Presenter taskflow. This task flow is added to a jspx page. The taskflow fetches the content from the contributor data file. The contributor data file is having a WYSIWYG editor. The content of the WYSIWYG editor is being displayed correctly through the task flow.
    We have some links in the WYSIWYG editor. These links again point to some data files. When we click on these links from within the portal, then we are getting a blank page(the url of this blank page is: http://localhost:7101/eWSIBPortal/faces/oracle/webcenter/sitestructure/render.jspx?datasource=UCM%23dDocName%3AWSIB_ARTICLE) and not displaying the content of the data file that we are pointing to from the WYSIWYG editor.
    We want to display the content of these data files(which we have pointed from WYSIWYG editor) in-line within the portal.
    Please help us to resolve this issue and let us know if any information is required from our end.

    Thanks for reply. However, can I use XSQL to dump the formated text to a file? or just can display to client through web browsers?

  • Downloading blob content from a custom table

    In our hosted Apex application, the following code from the Application Express Developer's Guide works great for allowing a user to download blob content from one of our custom tables via a download button. However, the code doesn't work on the Oracle Cloud because the "owa_util" package is no longer available. The code is as follows:
    CREATE OR REPLACE PROCEDURE download_my_file(p_file in number) AS
    v_mime VARCHAR2(48);
    v_length NUMBER;
    v_file_name VARCHAR2(2000);
    Lob_loc BLOB;
    BEGIN
    SELECT MIME_TYPE, BLOB_CONTENT, name,DBMS_LOB.GETLENGTH(blob_content)
    INTO v_mime,lob_loc,v_file_name,v_length
    FROM file_subjects
    WHERE id = p_file;
    -- 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
    owa_util.mime_header( nvl(v_mime,'application/octet'), 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: attachment; filename="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
    -- close the headers
    owa_util.http_header_close;
    -- download the BLOB
    wpg_docload.download_file( Lob_loc );
    end download_my_file;
    Besides using web services, does anyone know of a way to do this? Is there a way to add access to the "owa_util" package in the cloud? I have also tried apex_util.get_blob_file_src but that is also unavailable in the Oracle Cloud.
    Thanks,
    Steve

    Following Joel's advice:
    The way I solved this was to split the code between two page processes and one application process. The download button first calls a page process to move the report data into a blob column and then calls another page process which is of "run application process" type. This calls the application level process where the download code, shown below, is called.
    Notice the following changes to the code from the one posted earlier (also from Joel)
    1) added sys.htp.init;
    2) "sys." to all htp, owa and wpg_docload calls
    3) added apex_application.stop_apex_engine; after the wpg_docload statement at the bottom of the script.
    Now the download button launches a "save as" dialog box and the report content is downloaded to the client.
    The code now looks like:
    CREATE OR REPLACE PROCEDURE download_my_file(p_file in number) AS
    v_mime VARCHAR2(48);
    v_length NUMBER;
    v_file_name VARCHAR2(2000);
    Lob_loc BLOB;
    BEGIN
    SELECT MIME_TYPE, BLOB_CONTENT, name,DBMS_LOB.GETLENGTH(blob_content)
    INTO v_mime,lob_loc,v_file_name,v_length
    FROM oehr_file_subject
    WHERE id = p_file;
    -- 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
    sys.htp.init;
    sys.owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );
    -- set the size so the browser knows how much to download
    sys.htp.p('Content-length: ' || v_length);
    -- the filename will be used by the browser if the users does a save as
    sys. htp.p('Content-Disposition: attachment; filename="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
    -- close the headers
    sys.owa_util.http_header_close;
    -- download the BLOB
    sys.wpg_docload.download_file( Lob_loc );
    apex_application.stop_apex_engine;
    end download_my_file;
    Thanks Joel for your help.
    Steve

  • Display BLOB Image in a JSP page.

    Hi, Is there any easy way to display a Image in the browser using a JSP and an Oracle BLOB. I would like any code examples that anyone can provide me. I would like as many ways to do this as possible.
    Thanks Brian

    You can do it in 2 ways:
    1. Get the BLOB from the DB and then write it into the local harddisk where the Web Server is located and then give the path in the <IMG SRC> Tag.
    2. In the JSP, when you specify a IMG Tag
    <IMG SRC='FileDisplayServlet?hdImgName=new.gif'>
    This SRC is pointing to a Servlet. The Servlet will read the Query String and then go hit the DB, get the BLOB Content and then convert into a byte array. Now the servlet will change its content type to image or gif. Then it will write the content in the out stream.
    Hope this helps.
    Thanks and regards,
    Pazhanikanthan. P

  • Iframe of a Blob Content in Apex form/report

    Hi All
    I am developing a application where users will upload documents which will be stored in blob column. Now the requirement is to show the document with in the page using Iframe. Can some one please suggest the steps to show the blob content in iframe.
    Thanks in Advance.
    regards
    Srini.

    You can show the documents in an iframe only if your browser has an appropriate plugin (like to most browsers have it for pdf documents). Otherwise you will be forced to either save the document or open it with the appropriate programm. Means, your application will probably fail to show the documents in an iframe for all other document types other than pdf.
    I have no special case explaining how to display a document in an iframe but you can inspect it here:
    http://apex.oracle.com/pls/apex/f?p=31517:15
    and
    http://apex.oracle.com/pls/apex/f?p=31517:58
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    http://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • How to display BLOB image column with WEB application, JSF, ADF BC

    I looking for a way to display the content from a blob column on a WEB application, JSF, ADF BC
    The blob column contains a JPEG image.
    About the application
    The model contains a viewobject where the blob column attribute (photoimg) type is of type : BlobDomain
    Now I have to create the view to display the content of photoimg inside a JSF-JSP page.
    Any advice ?

    Search is your friend
    How to display the content of a BLOB column in a ADF/BC pages ?
    John

  • Display BLOBS

    I am trying to display BLOBS in HTMLDB using Report. I am not able to display images, PDF or Docs.
    I am using the following procedure DISPLAY_IMAGE
    create or replace procedure "DISPLAY_IMAGE"
    (p_image_id IN NUMBER)
    is
    l_mime varchar2(255);                
    l_length number;
    l_file_name varchar2(2000);
    lob_loc BLOB;
    begin
    select mime_type,image_data, file_name, dbms_lob.getlength(image_data)
    into l_mime, lob_loc, l_file_name, l_length
    from image_table where image_id = p_image_id;
                                       owa_util.mime_header(nvl(l_mime,'application/octet'), FALSE );      
    htp.p('Content-length: ' || l_length);
    htp.p('Content-Disposition: filename="' || l_file_name || '"');
    owa_util.http_header_close;
    wpg_docload.download_file( Lob_loc );
    end;
    I tried building with the following region source in the Report
    select
    '<iframe src="#OWNER#.display_image?p_image_id=&i.image_id." width=300> </iframe>' img, image_id, file_name, mime_type from image_table i
    Any ideas???

    Does accessing #OWNER#.display_image?p_image_id=&i.image_id. directly via your browser work if you replace &image_id. and #OWNER# with valid values (i.e. is a popup window displayed asking you to save or open the file)? If this works then...
    The HTTP header output by the following line tells a browser to popup the "Save to disk" dialog.
    htp.p('Content-Disposition: filename="' || l_file_name || '"');
    If you are wanting to just display the content of the file (e.g. image, pdf etc.) in the browser you will want to remove that line.
    [ BTW, I am not sure if you can set the src attribute of the IFRAME tag to be an image. PDFs should work though I think ]

  • How to change "Display column content" on a uploaded file link?

    Hi,
    I based my portal form on a table with a field of type BLOB. I used this to upload any type of file. I have no problem in uploading my file, when I query the information, a link comes up with the words "Display column content". I can click on that link to see the content of my file. But is there a way to change the wording "Display column content"?
    null

    Yoy can change the link by editing the generated package

Maybe you are looking for