Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

BLOB to JPG File

3247740Feb 23 2017 — edited Feb 23 2017

Hello,

I am getting an issue from the last one week, i am trying to download images from  table to jpg  but the image is getting extracted in red or green color. the jpg file size is coming 8kb which should be much higher

Table structure.

CREATE TABLE CF88IMAGE (NUMBER NUMBER, IMAGE BLOB);

ISSUE

while extracting with following script the jpg file is shrinked or coming in red color with following script.

CREATE OR REPLACE PROCEDURE "DOWNLOADPIC" (pi_number in NUMBER) IS

  l_file      UTL_FILE.FILE_TYPE;

  l_buffer    RAW(32767);

  l_amount    BINARY_INTEGER := 32767;

  l_pos       INTEGER := 1;

  l_blob      BLOB;

  l_blob_len  INTEGER;

  CURSOR C1 IS

  SELECT * FROM CF88image a

  where number=pi_number );

BEGIN

  FOR R1 IN C1 LOOP

     l_blob := r1.image;

     l_blob_len := DBMS_LOB.getlength(r1.image);

     l_pos := 1;

     -- Open the destination file.

  IF l_blob_len <32767 THEN

     l_file := UTL_FILE.FOPEN('BLOBS','image'||'.jpg','W', 32767);

     -- until complete.

     WHILE l_pos < l_blob_len LOOP

       DBMS_LOB.READ(l_blob, l_amount, l_pos, l_buffer);

       UTL_FILE.put_raw(l_file, l_buffer, TRUE);

       l_pos := l_pos + l_amount;

     END LOOP;

     -- Close the file.

     UTL_FILE.FCLOSE(l_file);

  END IF;

  END LOOP;

EXCEPTION

  WHEN OTHERS THEN

    -- Close the file if something goes wrong.

    IF UTL_FILE.IS_OPEN(l_file) THEN

      UTL_FILE.FCLOSE(l_file);

    END IF;

    RAISE;

END;

The attached image shows the download jpg file.

However through Oracle Form Builder i can see the proper image.

here is the download script of oracle form builder.

DECLARE

v_file_name varchar2(1000);

BEGIN

:System.Message_Level := '20';

go_block('cf88image');

:System.Message_Level := 0;

v_file_name := 'C:\ICBA\TMP\'||:cf88image.number||'.JPG';

WRITE_IMAGE_FILE(v_file_name,'JFIF','signature',no_compression,original_depth);

message('Downloaded Signature Completed !');

END;

Please help out

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 23 2017
Added on Feb 23 2017
10 comments
6,012 views