Decoding pdf data which was encoded as a single string
884210Nov 9 2011 — edited Nov 10 2011I am storing a single (very large BLOB) string which is a base64 encoding of a .pdf file.
If I try to decode the string I get a corrupted .pdf file.
Below is the code I'm using to decode...
blob_len := dbms_lob.getlength(pdf_blob);
--
offset := 1;
amount := 78;
DBMS_LOB.CREATETEMPORARY(blob_dec,true);
--
loop
if offset >= blob_len then
exit;
end if;
--
dbms_lob.read(pdf_blob,amount,offset,dec_buffer);
dbms_lob.append(blob_dec,utl_encode.base64_decode(dec_buffer));
offset := offset + amount;
end loop;
NOTE: I know the inital .pdf is fine because if I take the same .pdf file and encode it via Oracle's utl_encode.base64_encode facility, I can decode the data without any issue.
I do notice that the utl_encode.base64_encode creates individual lines of 76 characters in length with CR's at the end of each, whereas the string I need to work with is a single long string of 201,433 characters.
The string is coming in from an external webservice so I cannot influence its format.
I can't read in the string in a single dbms_lob.read call as iIm restricted to the size of the buffer RAW definition (i.e. 32767 ).
Any help appreciated.
anthony.