Displaying BLOB from Database

Hi All,
I am trying to preview a 'jpeg' image which is stored in my database. The images get inserted into the DB without any trouble, but on retrieving the images I get 'broken links' to the images. Please Help:
PROCEDURE GET_TEAM_LOGO(team_name VARCHAR2)
AS
vblob BLOB;
buf RAW(32000);
buf_size INTEGER := 32000;
offset INTEGER := 1;
len NUMBER;
mime_type VARCHAR2(30);
BEGIN
auth_proc;
-- get image_data and its mime type from the database
WHERE LOGO_ID=position;
htp.p('This is the value of team:'|| team_name ||'<br>');
SELECT logo_image, logo_type INTO vblob, mime_type
FROM LOGO_TABLE
WHERE group_name = team_name;
-- set the mime type for the http protocol
owa_util.mime_header('image/jpeg');
-- read the data with htp package
len:=dbms_lob.getlength(vblob);
WHILE offset < len LOOP
dbms_lob.read(vblob,buf_size,offset,buf);
htp.prn(utl_raw.cast_to_varchar2(buf));
offset:=offset+buf_size;
END LOOP;
-- check for exception
EXCEPTION
WHEN OTHERS THEN
htp.p(SQLCODE || SQLERRM);
END;
Thanks,
Peter

Hi!
I've used this code successfylly in a mod_plsql procedure.
Can be used as following:
htp.img('http://yourhost:port/<dad>/image.get_image?p_picture_id=123,'"right"',null,null,'width=107 height=66 border=1');
procedure get_image
( p_picture_id number
) as
cursor c_pict
( b_picture_id number
) is
select pict.picture -- blob column
, pict.format -- Gif/Jpeg etc.
from pictures pict
where pict.picture_id = b_picture_id
r_pict c_pict%rowtype;
v_blob BLOB;
v_amt NUMBER := 30;
v_off NUMBER := 1;
v_raw RAW(4096);
begin
open c_pict(p_picture_id);
fetch c_pict into r_pict;
if c_pict%notfound
then
close c_pict;
else
close c_pict;
owa_util.mime_header('image/'||r_pict.format);
begin
loop
dbms_lob.read(r_pict.picture,v_amt,v_off,v_raw);
htp.prn(utl_raw.cast_to_varchar2(v_raw));
v_off := v_off+v_amt;
v_amt := 4096;
end loop;
exception
when no_data_found
then
null;
end;
end if;
end get_image;

Similar Messages

  • How to display items from database using catagorylookupdroplet

    Hi everyone,
    i want to know how to display items from database using catagorylookup droplet. if anybody have any code snippet please share it.
    Thanks in advance,

    <dsp:droplet name=".................../CategoryLookup">
         <dsp:param name="id" param="itemId"/>
         <dsp:oparam name="output">
              <dsp:valueof param="element.displayName"/>
                   <%-- This is show the Child Category --%>
                   <dsp:droplet name="......................./ForEach">
                   <dsp:param name="array" param="element.childCategories"/>
                   <dsp:oparam name="outputStart">Child Categories</dsp:oparam>
                   <dsp:oparam name="output">
                        <dsp:a href="">//bydefault it will take its own file's name
                             <dsp:param name="itemId" param="element.repositoryId"/>                                                                                          <dsp:valueof param="element.displayName"/>
                        </dsp:a>
                   </dsp:oparam>                                             
                   </dsp:droplet>
                   <%-- This is show the Child Product --%>          
                   <dsp:droplet name=".............../ForEach">
                        <dsp:param name="array" param="element.childProducts"/>
                        <dsp:oparam name="outputStart">Child Products</dsp:oparam>
                                  <dsp:oparam name="output">
                                       <dsp:droplet name="................/ProductLookup">
                                            <dsp:param name="id" param="itemId"/>
                                            <dsp:param name="elementName" value="Prod"/>
                                            <dsp:oparam name="output">
                                                 <dsp:getvalueof id="img102" param="Prod.smallImage.url" idtype="java.lang.String">
                                                      <dsp:img height="250" width="250" src="<%=img102%>"/>
                                                 </dsp:getvalueof>
                                            </dsp:oparam>
                                       </dsp:droplet>
                                       <dsp:a href="productView.jsp">
                                            <dsp:param name="itemId" param="element.repositoryId"/>
                                            <dsp:valueof param="element.displayName"/>
                                       </dsp:a>
    Hope this helps.
    -RMishra

  • Display BLOB from remote database

    Context: We are offloading documents (pdf) from our OLTP database to a dedicated 'output database.' These documents must be displayed from the application on our OLTP database using a database link. Various posts show that querying a BLOB from a remote database can best be implemented using a query on the remote table and an insert on a local (temporary) table. So far, so good. The idea is to display this BLOB using wpg_docload.download_file.
    BUT:
    When trying to display the pdf from this global temporary table an error occurs:
    ORA-14453: attempt to use a LOB of a temporary table, whose data has already been purged
    When trying to display from a normal table and issuing a rollback after wpg_docload.download_file results in another error:
    ORA-22922: nonexistent LOB value
    When trying to display from a normal table and not removing the record in any way, its works fine. Only I now have a garbage collection issue, because the remote date remain in my local (preferably temporary) table.
    It seems to me that mod_plsql needs an active session to display my pdf.
    Does anyone have an explanation for this behaviour and maybe a solution for my problem?
    Environment:
    local: 10.2.0.4.0
    remote: 11.1.0.7.0
    pdf size: ca. 150kB
    code used:
    PROCEDURE show_doc (p_nta_id IN NUMBER
    ,p_sessie IN NUMBER
    IS
    t_lob BLOB;
    t_lob2 BLOB := empty_blob();
    t_mime VARCHAR2(100);
    BEGIN
    -- copy BLOB into local global temp table
    INSERT INTO mvs_tmp_notaprint_bestanden
    npv_nta_id
    , npv_npe_sessie
    , mime_type
    , bestand
    ) -- from remote table
    SELECT npd.npv_nta_id
    ,npd.npv_npe_sessie
    ,npd.mime_type
    ,npd.bestand
    FROM mvs_notaprint_bestanden@marc npd
    WHERE npd.npv_nta_id ; = p_nta_id
    AND npd.npv_npe_sessie = p_sessie
    -- show BLOB from local global temp table
    SELECT t.bestand
    , t.mime_type
    INTO t_lob
    , t_mime
    FROM mvs_tmp_notaprint_bestanden t
    WHERE t.npv_nta_id ; = p_nta_id
    AND t.npv_npe_sessie ; = p_sessie
    t_lob2 := t_lob; -- buffer BLOB
    owa_util.mime_header(t_mime , FALSE );
    owa_util.http_header_close;
    wpg_docload.download_file(t_lob2);
    END show_doc;

    Andrew,
    thank you, the 'preserve rows' did the trick.
    Every query from a browser (even in the same browser session) is a new Oracle session, so the copied records in the global temporary table are gone after the page is displayed.
    Am I correct in assuming that each call from the browser results in a new Oracle session? I did a few tests and found for each call a different sessionid.
    Sincerly,
    Arne Suverein
    Edited by: Arne Suverein on Aug 18, 2009 3:35 PM

  • How to show in a report a pdf blob from database

    Hi all
    We are working on report 6i and report 10. We have a report wich needs to show a blob field from database that storages a pdf (type application/pdf). OLE2 is deprecated. The pdf blob field must be displayed in a preview and must be printed. In local, it works. When it works on a browser, the pdf blob field is missing. If we load the field into a pdf file, the field is not visible in the browser.
    Do not get it to work. How I can implement? Could you give us any example for this?

    In local, it works. What do you mean by that exactly? You see the pdf in Reports Builder?
    If you just want to show the pdf in a browser (not embedded in a report) it is easy to use mod_plsql. You can have a simple db procedure like this to show any kind of blob:
    procedure show_webdoc(io_blob    in out nocopy blob
                         ,i_mimetype in varchar2
                         ,i_filename in varchar2)
    is
    begin
       if dbms_lob.getlength(io_blob) >0 then
          owa_util.mime_header(nvl(i_mimetype,'application/octet'),false);
          htp.p('Content-length: ' || dbms_lob.getlength(io_blob));
          htp.p('Content-Disposition:  inline; filename="'||i_filename|| '"');
          owa_util.http_header_close;
          wpg_docload.download_file(io_blob);
       end if;
    end show_webdoc;

  • Display image from database with jspSmart

    Hi
    I have successfully uploaded and saved images into oracle(8.1.5) table DATA_TYPE(dtid number, iconname varchar2(30), icon blob). When I try to display a specific icon in my browser, I get "javax.servlet.ServletException: General error" at:
    PreparedStatement pstmt = myConnection.prepareStatement(mySQL);
    My code looks like this:
    imgModifyDataType.jsp
    <%
    ResultSet myResultSet = null;
    Statement myStatement = null;
    Connection myConnection = null;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    myConnection = DriverManager.getConnection("Jdbc:Odbc:Te","te","te");
    String iconName;
    String pDTID = request.getParameter("dtid");
    String mySQL = "Select iconname, icon from data_types where dtid=?";
    PreparedStatement pstmt = myConnection.prepareStatement(mySQL);
    pstmt.setString(1,pDTID);
    myResultSet = pstmt.executeQuery();
    iconName = myResultSet.getString("iconname");
    myUpload.initialize(pageContext);
    myUpload.downloadField(myResultSet,"icon","application/x-msdownload", iconName);
    %>
    I call this JSP from another JSP like this:
    <img src="imgModifyDataType.jsp?dtid=<%=pDTID%>">
    If we cannt display image with the help of another jsp like this then please guide me how to modify the imgModifyDataType.jsp to a servlet because I have never worked in servlets.
    Please help
    Sajid

    I think that it may help you get image from database. I used two jsp page. First one is getphoto.jsp that makes as table based in sql statment and invoke the getimage.jsp this last returns images based on
    the getphoto.jsp PhotoId.
    /** getphoto.jsp source code */
    <%@page import="java.sql.*,oracle.jdbc.*"%>
    <html>
    <head>
    <title>
    jsp1
    </title>
    </head>
    <body bgcolor="#ffffff">
    <table width="781" border="2">
    <tr<<td>
    <td width="83" bgcolor="#C0C0C0"><b>PhotoId</b><td width="450" bgcolor="#C0C0C0"><b>Description</b></td><td width="228" bgcolor="#C0C0C0"><b>Photo Image</b></td>
    <%
    Connection conn = null;
    Statement stmt = null;
    ResultSet rset = null;
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection("jdbc:oracle:thin:@itas:1521:oraITAS","yourDbUserId","yourDbPassword");
    stmt = conn.createStatement();
    rset = stmt.executeQuery("select photo_id,photo_description from photo");
    while (rset.next()) {
         %>
         <tr><td width="83"><%=rset.getObject("photo_id")%></td><td width="450"><%=rset.getObject("photo_description")%></td><td width="228"><img src="getimage.jsp?PhotoId=<%=rset.getObject("photo_id")%>" width="238" height="228"></td></tr>
         <%
    conn.close();
    %>
    </table>
    </body>
    </html>
    /** getimage.jsp source code */
    <%@ page contentType="image/jpeg; chaoResult=iso-8859-1" language="java" import="java.sql.*,java.io.*,java.util.*" errorPage="" %>
    <%
    String strConnString = null;
    Connection oDbConn;
    Statement oStmt;
    ResultSet oResult;
    String strConnection = null;
    String strUserId = "c_erober";
    String strUserPwd = "sybdev99";
    String strDatabase = "oraITAS";
    String strPhotoId;
    strConnString = "jdbc:odbc:" + strDatabase;
    String strSql;
    try {
    strPhotoId = (String) request.getParameter("PhotoId");
    strSql = "select photo_image from photo" + ( (strPhotoId==null) ? " where photo_id = '001'": (" where photo_id = '" + strPhotoId + "'") );
    DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
    oDbConn = DriverManager.getConnection(strConnString,strUserId,strUserPwd);
    response.setContentType("image/jpeg");
    oStmt = oDbConn.createStatement();
    oResult = oStmt.executeQuery(strSql);
    oResult.next();
    byte[] bytearray = new byte[4096];
    int size=0;
    InputStream sImage;
    sImage = oResult.getBinaryStream(1);
    response.reset();
    response.setContentType("image/jpeg");
    response.addHeader("Content-Disposition","filename=getimage.jpeg");
    while((size=sImage.read(bytearray))!= -1 ) {
    response.getOutputStream().write(bytearray,0,size);
    response.flushBuffer();
    sImage.close();
    oDbConn.close();
    } catch (SQLException ex) { ex.getMessage();
    %>

  • Display Images from Database

    Hi all,
    I require to display images stored in database along with textual description of it on a JSP.
    The image file should not be stored intermediately on file system (i.e w/o using img HTML tag)
    It is a typical shopping cart appln. where images are fetched from database and the associated description is displayed along side.
    Please note that it is the case of Mixed content types(text and binary data).
    Thanks and Regards

    Like "Breakfast" said, you can do this with a servlet that retrieves your images from a database....
    if you create a servlet to do this, you would have a generic servlet which retrieves a picture from a database based upon a key which could be a picture name or number.
    Lets say the file is out there in the database as a BLOB or Binary Image... you could have this kind of code in the doPost(HttpRequest req, HttpResponse res) or doService(HttpRequest req, HttpResponse res) method.
    The table holding the image has at least two columns one called IMAGE which holds the binary image and the other called FILENAME. If the connection to the DB is already open, you do something like this.
    String fileToGet = (String)req.getParameter("FILENAME");
    rs = conn.createStatement().executeQuery("select from IMAGE_TABLE where FILENAME='" + fileToGet + "'");
    if(rs.next())
    InputStream in = rs.getBinaryStream("IMAGE");
    res.setContentType("image/jpg"); // or whatever type of file it is.
    ServletOutputStream sout = res.getOutputStream();
    int c;
    while((c = in.read()) != -1)
    sout.write(c);
    in.close();
    sout.close();
    This should write your image to the response output of the servlet.
    Now, where you want your image, you put.
    <img src="/servlet/ImageServlet?FILENAME="thefileIwant">
    This should do what you want... Use your favorite pipe copy method to get the input stream to the output stream. If you are worried about overhead and scaling like "breakfast" said (it CAN be a problem in high access sites), then you can add an image caching scheme and get really complex.... But this is a rough idea on what to do.
    Hope this helps.
    Stephen McConnell

  • Help, how to open and display blobs from tables

    Dear all,
    I am trying to store ms-word files on a table using a blob column.
    Does anyone how to open the files and display them from a form using 9iAS?
    Thank you.
    Carlos.

    And there may be, but you won't likely find that here. Do some time searching Google and maybe you'll find code that someone was nice enough to make freely available, although I wouldn't count on it. Were i a programmer and took the time to read those docs and write the code, I'd want to be paid for my time. But there are a lot of programmers who swear by freeware! You may get lucky.

  • Displaying image from database in report

    I need to include a picture (company logo) in numerous reports. This logo will be stored in an MS SQL Image field in a table (this bit I have already sorted out).
    What I'm wondering is, what is the best way to retrieve this image from the database? Do I just include it in the view the report runs off? I'm hesitant to do this, as the view may return back hundreds of records, which means (I think) it will be sending the image along with it hundreds in time.
    In short:
    1) What is the best way to pass an image to a report.
    2) If I include the Image field in a view which returns back hundreds of line, will the image be returned also hundreds of time, causing network congestion/performance issues?
    3) If so (2), is there a way of sending the image only once, no matter how many rows are in the returned view?
    Thanks.

    Hi Shanon,
    We can display the image by making it a local copy on your machine.
    If it is possible to  get the image saved on local copy.
    If we place the image in detail section then it would return one record.
    As the image is from Database, so it would hit the database very time when you refresh the report and place it in Report Header or report fotter.
    So, place your logo as an OLE object in report and would reduce processing time.
    Regards,
    Naveen.

  • Help with displaying info from database+asp

    How can I display info from a database so that it is
    formatted into rows in a table
    here is an example of what I would like
    http://www.westerveltcollege.com/new/programs/bus_admin_computers.html
    (it is the section that show the course content)
    I know it has been code into the table but how to do this
    dymanically
    hope that makes sense to someone ;)

    To do it properly you would set up two tables. The first
    would contain the
    topics and be something like this
    topicID
    topicName
    Then you would have a second table that would hold the
    content like this
    contentID
    contentName
    topicID
    The last field links this table to the topic.
    To display them you would link the topics into a master list,
    and then pass
    the topicID to the page displaying the content and use the
    topicID as a
    filter on the content table.
    Paul Whitham
    Certified Dreamweaver MX2004 Professional
    Adobe Community Expert - Dreamweaver
    Valleybiz Internet Design
    www.valleybiz.net
    "jnc1965" <[email protected]> wrote in
    message
    news:eeot1q$db0$[email protected]..
    > nice one thanks
    >
    > now one more quetion
    > how do I set up the info in the database
    > I have serveral page for different topics and each page
    has a table like
    > mentioned above
    > I dont want to make a different colunm for each for the
    course contents
    > I would like to build one table and have each subject's
    course content in
    > a
    > column but how would I do this?
    > and still have appear like the example
    >

  • How to display data from Database individually??? Anyone can help ?

    HI,
    i i had select a row of data from database using ,
    /* Query * From Table RESOURCEORDER where po = selected no and project = selected project */
         public ResultSet getAllData() throws SQLException
         getConnection();
         Statement stmt = conn.createStatement();
         ResultSet rs = stmt.executeQuery("SELECT * FROM RESOURCEORDER WHERE PROJECT = '" + getSelProject() + "' and PURCHASEORDERNO = '" + getPo() + "'" );
         return rs;
    After that , how do i display the data individually ?
    Eg select data is ('projectA','7891203-1', '10-4-2005','lcd',2000,'121-45217-8','electrical','pending','donwong')
    i want to display them individually, like this in a page
    Projectname: /* should display the Project A*/
    P.O no:
    Date:
    Order:
    Cost:
    Acc no:
    Type:
    status:
    Orderedby:
    Can anyone help ? cos i'm new to JSP ......Thanks alot!!!!!
    Regards,
    khim

    I assume PO being a unique key, will always return 1 row from db.
    public String[] getAllData() throws Exception
    getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM RESOURCEORDER WHERE PROJECT = '" + getSelProject() + "' and PURCHASEORDERNO = '" + getPo() + "'" );
    String [] returnValue = new String[9];
    while(rs.next())
    returnValue[1] = rs.getString("colname");
    returnValue[2] = rs.getString("colname");
    ///and so on
    return returnValue;
    }Once you get that you could individually view it by setting a loop to run through the returned array.
    Hope it helps

  • Getting blobs from databases

    Hi!
    Im trying to get a blob from a database and write it to a file, but I just can't get the Blob value, I just recieve the adress. I've tried InputStream and getBytes but none of them does what I want. getBytes where closest but because it requires two inparameters (long pos, int length) and blob.length gives an long i can't figure out how many bytes to get. Anyone got any sugestions?

    Agrawal.
    I've read through both those pages (even thou i've already managed to make the connection to mysql) and I still can't work around my problem. the method getBytes(), requires two parameters, one that tells it where to start reading and one telling it how long it should read. If I leave one out it will inevitable lead to problems. So I still need to figure out a way to get the length of the blob in a int to make this work. but since the blob.length() method returns a long wich I can't convert I'm stuck!

  • Dowload blobs from Database

    I know this is not the best way to store files but I have inherited an old php script which I am converting to CF because php is useless.
    Now i have a script to do this in php but can this be achived with CF? It is just a quick fix until I have time to rework the CMS
    <?php
    if(isset($_GET['id']))
    // if id is set then get the file with the id from database
    $id    = $_GET['id'];
    $query = "SELECT name, type, size, content " .
             "FROM upload WHERE id = '$id'";
    $result = mysql_query($query) or die('Error, query failed');
    list($name, $type, $size, $content) =                                  mysql_fetch_array($result);
    header("Content-length: $size");
    header("Content-type: $type");
    header("Content-Disposition: attachment; filename=$name");
    echo $content;
    i
    exit;
    ?>

    My php experience is NILL, but applying basic coding experience I believe your CFML will be close to this.
    <cfif structKeyExists(url,"id")>
      <cfquery datasource="..." name="result">
        SELECT name,type,size,content
        FROM upload
        WHERE id = <cfqueryparam value="#url.id#" cfsqltype="cf_sql_integer">
      </cfquery>
      <cfheader name="Content-Disposition: atachment; filename=#result.name#">
      <cfcontent type="#result.type#" reset="yes">
      #result.content#
    </cfif>
    If any of this content can be binary, then you may also need to use one or more of the toBinary() toBase64(), isBinary(), binaryDecode() or other relevant functions.

  • ADF: Display image from database

    Hi,
    I've found a number of threads addressing this issue, but none that have solved my problem as yet. I'm trying to display an image from a database column in JDev 10.1.3.2.0. I've found an article in the Help that sounds like it's describing exactly what I need:
    To insert a databound image control into a form or panel: In the ADF Swing project, open the Java Visual Editor on the desired data panel or form. From the View menu choose Data Control Palette to open the palette. In the Data Control Palette, drag the attribute you want to bind to the image control into the open form or panel. From the Add Child popup list, select JUImageControl. JDeveloper adds code to the class file to bind the JUImageControl to the attribute
    The problem I'm having is that this doesn't bear any relation to what I can see. I'm presuming that the Java Visual Editor is the design tab of the jsp page editor, as this is the only visual editor I can find. If it isn't, that would explain why this doesn't work... When I drag my attribute, I have to select what type of item I want it to be. I can't find an Add Child popup anywhere.
    I have a horrible feeling that this is a very stupid question, but I'm completely stuck.

    The help-text you found refers to an ADF-Swing project, not a web application with JSP's. This post: How to display the content of a BLOB column in a ADF/BC pages ? shows you how to do it with ADF Faces.

  • Alternative ways of displaying image from database?

    hi - I'm working with some legacy/inherited/already-written Forms that just use block triggers to 'select values into :Fields..' to populate the text boxes on the canvas.
    Whenever I've managed to display db-based images before, it's always been on blocks that are based just on the table, and Forms shows the image okay.
    These forms I'm using at the moment though aren't based on tables, they just get populated from the trigger.
    I don't believe you can select into a blob/image, or at least I haven't been able to get that to work.
    Are there any alternative ways of populating an image place-holder, with a blob field from the database? (other than using a table-based block)??
    thanks.

    May be you can separate the image item to a DB block with primary key of the table and create a relation between two blocks. So when the first block is populated through trigger, it would fetch the image on 2nd block automatically.

  • Problem to display image from database

    i also waiting when this practical will come to the end la..really boring..mrhanafi came 2 weeks ago..he didnt check anyhting..he was there for 15 mins only..hey dont play ponteng la..after this friday you ponteng how many days you want;)

    Using JHeadstart, you can display a BLOB column from the database in HTML, by way of ADF. Check out the JHeadstart Tutorial at http://www.oracle.com/technology/products/jdev/tips/muench/jhstutorial/index.html to get started, then do the same for your own database tables that include the BLOB column. JHeadstart will take care of rendering it as a file upload or image, depending on the display type you set at the attribute level.
    Hope this helps,
    Sandra Muller
    JHeadstart Team
    Oracle Consulting

Maybe you are looking for

  • Domain name and  session

    Hi , We have deployed our application on tomcat server built on struts framework. We have also set the domain name and are redirecting the domain name to Static Ip where our application is deployed with URL Masking option enabled. Everything is worki

  • Verify now doesn't work

    Rented last week.  Now cant

  • DMS in IS Utility

    HI, Is DMS - Document Management System  is part of standard IS Utility package. Looking for any inputs that will be helpful. Anirudh,

  • 7110 and The specified domain controller could not be contacted

    Hello, Running a 7110 with 2010.Q3.2.0 Software Release and can't seem to join a Windows 2008 SP2 x64 Active Directory Domain. I get the following: error: The specified domain controller could not be contacted, or the domain is invalid for the contro

  • Help with running servlet with jakarta tomcat

    I had recently created a couple of java servlets and wanted to run them. I had put the .class files in Tomcat 4.1\webapps\Root\ then typed in http://localhost:8080/ then the servlet in the web browser. Here was the error page copied and pasted. If I