View Full Version : Probs - reading to/from - PDF to BLOB...
Thomas Kyte
03-26-2005, 11:48 AM
In article <qwh1e.107589$Vf.4091205@news000.worldonline.dk>, Verner Jensen,
Ålborg says...Howdy !Via Tom Kyte's site - I found two routines for reading/writing - a PDF fileto/from database. See below.Question I've tried to read/write the same PDF and GIF - file - but bothtimes the output file - which should be identical to the input file - endedup different/corrupted?Using Xp, 10g - same for in/out.............
version of database?
have you analyzed what is different -- off by a byte or total garbarge?
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:6379798216275#19264891198142
shows what I've found to be the "neatest" way to get the blob out -- ftp.
Any suggestions?Rgds, Henrik
--
Thomas Kyte
Oracle Public Sector
http://asktom.oracle.com/
opinions are my own and may not reflect those of Oracle Corporation
Verner Jensen, Ålborg
03-26-2005, 07:05 PM
Howdy !
Via Tom Kyte's site - I found two routines for reading/writing - a PDF file
to/from database. See below.
Question I've tried to read/write the same PDF and GIF - file - but both
times the output file - which should be identical to the input file - ended
up different/corrupted?
Using Xp, 10g - same for in/out.............
Any suggestions?
Rgds, Henrik
Listing 1)
CREATE OR REPLACE procedure ins_file_in_blob is
l_blob blob;
l_bfile bfile;
begin
insert into files_org (id, content) values ( 1, empty_blob() )
returning content into l_blob;
-- Using directory here....
l_bfile := bfilename( 'MY_FILES', 'input.gif');
dbms_lob.fileopen( l_bfile );
dbms_output.put_line('Length of file : ' || dbms_lob.getlength( l_bfile ));
dbms_lob.loadfromfile( l_blob, l_bfile, dbms_lob.getlength( l_bfile ) );
dbms_lob.fileclose( l_bfile );
end;
/
Listing 2)
create or replace procedure extract_blob_to_pdf is
vblob blob;
vstart number:=1;
bytelen number := 32000;
len number;
my_vr raw(32000);
l_output utl_file.file_type;
p_file varchar2(30) default 'output.pdf';
begin
-- Using a directory here.....
l_output := utl_file.fopen('MY_FILES', p_file, 'w', 32760);
for l_cur in (SELECT CONTENT from files_org where id = 1 and rownum = 1)
loop
len := DBMS_LOB.GETLENGTH(l_cur.content);
vblob := l_cur.content ;
dbms_output.put_line('Length of the Column : ' || to_char(len));
vstart := 1;
while (vstart < len) loop -- loop till entire data is fetched
dbms_output.put_line('vstart : ' || to_char(vstart));
DBMS_LOB.READ(vblob,bytelen,vstart,my_vr);
utl_file.put_raw(l_output,my_vr);
utl_file.fflush(l_output);
vstart := vstart + bytelen ;
end loop;
utl_file.fclose(l_output);
end loop;
end;
Verner Jensen, Ålborg
03-26-2005, 10:50 PM
Hi' Tom ! Thanx for answering in this forum.
Actually - I haven't fine-analyzed the two different files, But:
1) They appear to have the same size in OS.
2) Number of bytes read in/written out - is exactly identical.
3) DB - 1010.
4) OS - XP.
The funny thing is, when I opened the output PDF file - left
handside-bookmarks were correct - but the "body"/piece in the center was
missing...
I recall another one with the same experience - and you suggested to check
NLS settings. But I use the samme DB - for in and out...
/rgds, Henrik
"Thomas Kyte" <thomas.kyte@oracle.com> wrote in message
news:121866501.0001529b.054@drn.newsguy.com... In article <qwh1e.107589$Vf.4091205@news000.worldonline.dk>, Verner Jensen, Ålborg says...Howdy !Via Tom Kyte's site - I found two routines for reading/writing - a PDFfileto/from database. See below.Question I've tried to read/write the same PDF and GIF - file - but bothtimes the output file - which should be identical to the input file -endedup different/corrupted?Using Xp, 10g - same for in/out............. version of database? have you analyzed what is different -- off by a byte or total garbarge? http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:6379798216275#19264891198142 shows what I've found to be the "neatest" way to get the blob out -- ftp.Any suggestions?Rgds, Henrik -- Thomas Kyte Oracle Public Sector http://asktom.oracle.com/ opinions are my own and may not reflect those of Oracle Corporation
Verner Jensen, Ålborg
03-26-2005, 11:19 PM
Hi' - Found out.
I just copied the code without further notice. The write-to-file routine had
'w' in the utl_file.fopen. Replacing this with 'wb' - did the job....
Thx, again
"Thomas Kyte" <thomas.kyte@oracle.com> wrote in message
news:121866501.0001529b.054@drn.newsguy.com... In article <qwh1e.107589$Vf.4091205@news000.worldonline.dk>, Verner Jensen, Ålborg says...Howdy !Via Tom Kyte's site - I found two routines for reading/writing - a PDFfileto/from database. See below.Question I've tried to read/write the same PDF and GIF - file - but bothtimes the output file - which should be identical to the input file -endedup different/corrupted?Using Xp, 10g - same for in/out............. version of database? have you analyzed what is different -- off by a byte or total garbarge? http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:6379798216275#19264891198142 shows what I've found to be the "neatest" way to get the blob out -- ftp.Any suggestions?Rgds, Henrik -- Thomas Kyte Oracle Public Sector http://asktom.oracle.com/ opinions are my own and may not reflect those of Oracle Corporation
MyLounge.com Site Map
Forum:
Cars,
Cell Phone,
Database,
Games,
Home Improvement,
IT,
Music,
School,
Sports,
Web Design,
Web Server,
Weight Loss
The MyLounge.com forum is intended for informational use only and should not
be relied upon and is not a substitute for any advice. The information contained
on MyLounge.com are opinions and suggestions of members and is not a representation
of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for
the accuracy, completeness or usefulness of any postings or the qualifications
of any person responding. Please consult a expert or seek the services of an
attorney in your area for more accuracy on your specific situation. Please note
that our forums also serve as mirrors to Usenet newsgroups. Many posts you see
on our forums are made by newsgroup users who may not be members of MyLounge.com
Term of Service
vBulletin v3.0.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.