problem occur load image using blob
DBAsupport.com Forums - Powered by vBulletin
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: problem occur load image using blob

  1. #1
    Join Date
    Nov 2006
    Posts
    3

    problem occur load image using blob

    hi
    guys

    pls help me,,



    1) i m trying to store load image to oracle 9i release pack 1,
    at the time of loading image using procedure,, it's shows me an error .

    so pls help


    CREATE TABLE images (
    id NUMBER(10) NOT NULL,
    name VARCHAR2(50) NOT NULL,
    image BLOB NOT NULL
    )
    /

    ALTER TABLE images ADD (
    CONSTRAINT images_pk PRIMARY KEY (id)
    )
    /

    ALTER TABLE images ADD (
    CONSTRAINT images_uk UNIQUE (name)
    )
    /

    CREATE SEQUENCE images_seq
    /

    CREATE OR REPLACE DIRECTORY image_dir AS 'C:\'
    /

    Create PL/SQL Code
    Next we create the code to load and retrieve the images:

    CREATE OR REPLACE PACKAGE Images_API AS

    PROCEDURE Load (p_name IN images.name%TYPE);
    PROCEDURE Get (p_name IN images.name%TYPE,
    p_type IN VARCHAR2 DEFAULT 'gif');

    PROCEDURE Get_Gif (p_name IN images.name%TYPE);
    PROCEDURE Get_Jpeg (p_name IN images.name%TYPE);

    END;
    /

    CREATE OR REPLACE PACKAGE BODY Images_API AS

    PROCEDURE Load (p_name IN images.name%TYPE) IS
    v_bfile BFILE;
    v_blob BLOB;
    BEGIN
    INSERT INTO images (id, name, image)
    VALUES (images_seq.NEXTVAL, p_name, empty_blob())
    RETURN image INTO v_blob;

    v_bfile := BFILENAME('IMAGE_DIR', p_name);
    Dbms_Lob.Fileopen(v_bfile, Dbms_Lob.File_Readonly);
    Dbms_Lob.Loadfromfile(v_blob, v_bfile, Dbms_Lob.Getlength(v_bfile));
    Dbms_Lob.Fileclose(v_bfile);

    COMMIT;
    EXCEPTION
    WHEN OTHERS THEN
    ROLLBACK;
    RAISE;
    END;

    PROCEDURE Get (p_name IN images.name%TYPE,
    p_type IN VARCHAR2 DEFAULT 'gif') IS
    v_blob BLOB;
    v_amt NUMBER := 30;
    v_off NUMBER := 1;
    v_raw RAW(4096);
    BEGIN
    SELECT image
    INTO v_blob
    FROM images
    WHERE name = p_name;

    Owa_Util.Mime_Header('image/' || p_type);

    BEGIN
    LOOP
    Dbms_Lob.Read(v_blob, 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;

    PROCEDURE Get_Gif (p_name IN images.name%TYPE) IS
    BEGIN
    Get (p_name, 'gif');
    END;

    PROCEDURE Get_Jpeg (p_name IN images.name%TYPE) IS
    BEGIN
    Get (p_name, 'jpeg');
    END;

    END;
    /

    Load Images
    Next we load some images into the database:

    EXEC Images_API.Load('save.gif');



    i get error,,

    ERROR at line 1:
    ORA-22288: file or LOB operation FILEOPEN failed
    The system cannot find the file specified.
    ORA-06512: at "TIUMAS.IMAGES_API", line 20
    ORA-06512: at line 1




    2) can i use same thing to load .doc or .txt files.


    if u find better way than it,, let me know

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,331
    well does the file exist in the place the database is looking for it

  3. #3
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,684
    By the way, you could have linked to my article:

    http://www.oracle-base.com/articles/...OverHTTP9i.php

    Rather than republish all the source code on this forum.

    Did you know republishing internet content is a breach of the Digital Rights Act?

    Cheers

    Tim...
    Tim...
    OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
    OCA PL/SQL Developer
    Oracle ACE Director
    My website: www.oracle-base.com
    My blog: www.oracle-base.com/blog

  4. #4
    Join Date
    Jan 2001
    Posts
    2,828
    Hi Tim

    I did not know that the content on your site is copyrigthed.

    By the way i had used the contents of your site primarily when i was doing OCP exams for 9i.Books werent available then i had taken printouts and distrubted to my friends.

    on second thoughts you should have mentioned all those as copyrighted material soemwhere on your site as footer or header.

    regards
    Hrishy

  5. #5
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,331
    so the copyright and disclaimer link just passed you by?

  6. #6
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,684
    Hi.

    I'm not having a go at the Zalak or anyone else here, I just think it is worth explaining some stuff.

    Everything displayed on the internet has an implicit copyright, regardless of copyright statements. That's just the way it is. Even this comment is subject to the same rules! Some countries have formal legislation upholding this. In in the USA they have the Digital Copyright Act. In Europe I think it's called the European Union Copyright Directive. They all amount to much the same thing.

    Anyway, I have no problem with people reading, and linking to my stuff. That's why it is on the net. I also don't mind if people print out articles to read when they are away from the computer. I do get annoyed when people cut & paste whole chunks of articles, rather than linking to them. It is after all illegal.

    I'm a little sensitive to this stuff these days since I've had the whole of my website ripped and republished on other domains twice in recent months. No doubt people will read this and think, "get over yourself", but if you let one thing slip, people start thinking it's OK and before you know it everyone is doing it.

    Anyway, I'll retire to my dark cellar now...

    Cheers

    Tim...
    Tim...
    OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
    OCA PL/SQL Developer
    Oracle ACE Director
    My website: www.oracle-base.com
    My blog: www.oracle-base.com/blog

  7. #7
    Join Date
    Nov 2006
    Location
    Sofia
    Posts
    630
    Chesk where IMAGE_DIR points to. It could happen that the directory points to different path

  8. #8
    Join Date
    Jul 2002
    Location
    Northampton, England
    Posts
    612
    Quote Originally Posted by TimHall
    I'm a little sensitive to this stuff these days since I've had the whole of my website ripped and republished on other domains twice in recent months. No doubt people will read this and think, "get over yourself", but if you let one thing slip, people start thinking it's OK and before you know it everyone is doing it.
    [rant]I agree with you whole-heartedly. If someone prints work in any format without first crediting the author it is a clear infringement of copyright.

    I write novels in my spare time and someone who I trusted to give me a review of a portion of one of my books, decided to post what I had given them on the net. They did it with the best of intentions, but that isn't really the point. It was my work and I should decide on where it does or does not go.[/rant]
    Assistance is Futile...

  9. #9
    Join Date
    Nov 2006
    Location
    Sofia
    Posts
    630
    Guys,
    The discussion is really interesting but it has little to do with loading images in LOBs

  10. #10
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,684
    OK. I agree. I have successfully manages to hijack this thread. Sorry!

    As previous people have said, your directory is pointing to "C:\" and you are attempting to load the image "save.gif".

    Does the file "C:\save.gif" exist on your database server? If not, then that is your problem.

    If it does exist, please post back.

    Cheers

    Tim...

    And sorry again for hijacking this thread.
    Tim...
    OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
    OCA PL/SQL Developer
    Oracle ACE Director
    My website: www.oracle-base.com
    My blog: www.oracle-base.com/blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width