Base64 to Blob
Hi guys,
I am not an oracle expert. I am trying to insert a base64 data into a Blob. I was trying to use :
INSERT INTO MyDB.EXCELFILETABLE(FILELID,SPREADSHEETDATA,OWNER) values
( 1, utl_encode.base64_decode(utl_raw.cast_to_raw(b64Doc)),'owners' )
b64Doc is a base64 type string. I get the whole file as a base64 type.
I am getting this error that long can only be insert as Long. I get that RAW is actually a LONG. I don't understand that the method actually takes RAW so why it doesnt work.
I have searched on the net and ppl propose using a procedure. Can it not be done within a single sql.
I will really appreciate any help here.
thanks
mahdi
within the xml tag i receive this base64 encoded string...
<EngineerSignature type="jpeg">Qk3KCQAAAAAAAHYAAAAoAAAA6QAAAFUAAAABAAQAAgAAAFQJAAAAAAAAAAAAABAAAAAAAAAAAAAAAICAgACAAAAAgIAAAACAAAAAgIAAAACAAIAAgAD///8AwMDAAP8AAAD//wAAAP8AAAD//wBAAP8A/wD/AOiIAoAAAOiIAoAAAOiIAoAAAOiIAoAAAOiIAoAAAOiIAoAAAOiIAoAAAOiIAoAAAMaIAooEqhyIAoAAAMKIAooIqgKoGogCgAAAwIgCigqqAqgaiAKAAAC+iAKKBqoACKiIiqoaiAKAAAC8iAKKBqoGiAAEiqoaiAKAAAC8iAaqCIgABIqqGogCgAAAuogGqgqIBKoaiAKAAAC4iAaqAqgKiAAEqqgaiAKAAAA4iAKKBKoCigSqcogGqgKoDIgABKqoGogCgAAAMogCihKqAqgkiAKKCKoCqDyIBqoCqAyIAAaKqqgAGogCgAAAMIgCihaqAqggiAKKDKoCqDiIBqoCqA6IBKociAKAAAAwiAiqAqgKiAaqAqgciAKKEKo2iAaqAqgQiASqHIgCgAAALogCigSqEogABoqqqAAaiAiqCIgEqgKoMogGqgKoEIgABoqqqAAciAKAAAAsiAKKBKoCqBSIBKoYiAiqCogABoqqqAAwiAKKBKoCqBKIBKoeiAKAAAAsiASqAqgWiAAGiqqoABSICKoOiAAEqqguiAKKBKoCqBKIAAaKqqgAHogCgAAALIgEqhiIAAaKqqgAEIgCiga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AooGqp6IAoAAACqIAooKqgyIBqqgiAKAAAAqiAaqAooEqgqIBqqiiAKAAAAoiAaqAASIigSqCIgGqgKooogCgAAAJogGqgKoBIgEqgSIAooGqgKopIgCgAAAJIgCigSqAqgGiASqAASIigaqAqimiAKAAAAiiAKKBqoIiAyqqogCgAAAIIgCigaqCogCigiqrIgCgAAAHogCigaqDIgIqq6IAoAAAByIAooGqgqIAooGqgKosIgCgAAAHIgGqgqIAooIqgKosIgCgAAAGogGqgKoCIgIqgKIBKqwiAKAAAAYiAaqAqgGiAqqBIgEqrCIAoAAABaIBqoCqASIAooIqgKoBogABoqqqACuiAKAAAAAAQ==</EngineerSignature>
is the best practice to then store this as the base64 format in table or as the decoded format??
how would i go about doing each...
ideally i would like some way of taking this base64 string decoding it and writing the image to file...
i will be recieving many of these xmls daily so is there a solution to this without using any registered schemas?
is this possible?
thanks
Similar Messages
-
Publish User Cert to AD after the fact
Hello all!
I was wondering if its possible to have the CA attempt to re-publish certs to AD after the fact (cert was already issued and an attempt was made to publish but failed) ?
Background - We didnt have our CA computer account in the "Cert Publishers" Group in our user domain. This led to event 80 being populated in the CA (Unable to publish to AD due to insufficent permissions)
I added our CA into that group and publishing to AD is working well but ONLY FOR NEW CERTS...
How do i tell the CA to attempt to publish the cert to AD for the already issued certs (Many...about 1000)
Thanks!I have accomplished my goal with the help of some VBS.
In a nutshell, this is the process i used
1) I first needed to create a text file containing serial numbers of the certificates i wanted to get imported into the User's AD Account (userCertificate). In my case there was about 1500 so this needed an automated way. This is the command i used to create
this text file
certutil -view -restrict "Disposition=20,CertificateTemplate=1.3.6.1.4.1.311........" -out SerialNumber > c:\Temp\Serials.txt
Disposition=20 Means Certificates that are Issued
CertificateTemplate=1.3.6.1.4.1.311........ Means the Custom Certificate Template OID that i am interested in
-out SerialNumber Means Output just the serial number
2) My next step was a need to take these serial numbers and somehow generate CER files for every one of them. I wrote a VBS script to parse through the above Serial Number text file and issue a command for every instance found. This is the command i used
from within the VBS file to generate a CER for the serials
oShell.Run ("%comspec% /c certutil -view -restrict ""SerialNumber=" & Values(1) & """ -out RawCertificate > c:\Temp\" & Values(1) & ".cer", 0 , True)
%comspec% /c allows the output of oShell.Run to be piped into a file
-restrict ""SerialNumber=" & aValues(1) & """ Means i am filtering the view to be limited/restricted to 1 certificate based on the serial number (Values(1)) is the serial number obtained from parsing 1 line of the Serials.txt File
-out RawCertificate Means spit out a Base64 Encoded blob and then pipe that to c:\Temp\" & Values(1) & ".cer (Once again the Values(1) refers to the parsed serial number. The file would look something like C:\Temp\1a2b3c4d5e6f1a2b.cer
3) I am now at a point where i have a directory (C:\Temp) full of CER files (my case was about 1500). I now need to import all of those CER files into Active Directory. The UPN is included in the certificate so when the command is issued, the certificate
is placed into the correct user's store without any additional modifications required. Once again i wrote a simple VBS script to Iterate through a Directory and for each file found run this command
oShell.Run ("%comspec% /c certutil -dspublish " & objFile.Path & " User", 0 , True)
certutil -dspublish Means Publish the file into AD
objFile.Path is the path to the individual CER file in the C:\Temp Directory
User instructs certutil to Publish the CER file to an Active Directory User (Obtained from the UPN attribute in the cert)
If anybody has any questions, or would like to request the individual VBS files, PM me anytime.
Thanks Fredrik for your assistance -
I have a BLOB column which contains BASE64 encoded jpegs.
I want to decode these from BASE64 such that I can get the original JPEG.
I've written a function to do this (based on an example found here but modified slightly since my source is a BLOB not a CLOB: http://blogs.dayneo.co.za/2012/07/base64-decode-using-plsql.html)
FUNCTION base64_decode(p_file IN BLOB)
RETURN BLOB IS
l_BASE64_LN_LENGTH constant pls_integer := 30000;
l_result blob := empty_blob();
l_pos number := 1;
l_amount number;
l_buffer raw(32767);
l_rbuf raw(32767);
l_length pls_integer;
begin
DBMS_LOB.createTemporary(l_result, true, dbms_lob.CALL);
l_length := DBMS_LOB.getLength(p_file);
while l_pos <= l_length loop
l_amount := l_BASE64_LN_LENGTH;
dbms_lob.read(p_file, l_amount, l_pos, l_rbuf);
l_buffer := utl_encode.base64_decode(l_rbuf);
dbms_lob.writeappend(l_result,
utl_raw.length(l_buffer),
l_buffer);
l_pos := l_pos + l_BASE64_LN_LENGTH;
end loop;
return l_result;
END base64_decode;This works absolutely fine where the input BLOB (p_file) is less than 30000 bytes i.e. I can save the generated BLOB and open it in a graphics application.
However, if the input BLOB (p_file) is larger than 30000 bytes, when I save the resultant BLOB (i.e. l_result) and try to open it with a graphics application such as Windows Picture Viewer I get the message "Drawing failed".
Any thoughts, comments or suggestions would be very much appreciated.
Thanks,
Andy>
This works absolutely fine where the input BLOB (p_file) is less than 30000 bytes i.e. I can save the generated BLOB and open it in a graphics application.
However, if the input BLOB (p_file) is larger than 30000 bytes, when I save the resultant BLOB (i.e. l_result) and try to open it with a graphics application such as Windows Picture Viewer I get the message "Drawing failed".
>
You can't just append and try to decode an arbitrary number of bytes in your loop. You are like having this problem
>
Conversion needs to be done in properly aligned chunks. And I use base64 conversions for MIME purposes.
>
See the solution by Oracle ACE Billy Verreynne Posted: May 29, 2012 9:28 AM at
Re: BASE64 (PDF) CLOB to BLOB -
BASE64 (PDF) CLOB to BLOB
Hello everybody! I have to convert a BASE64 representation of a PDF file to BLOB. I found one example on the Internet but there is something wrong with it and I can't figure it out.
create or replace function decode_base64(p_clob_in in clob) return blob is
v_blob blob;
v_offset integer;
v_buffer_varchar varchar2(32000);
v_buffer_raw raw(32000);
v_buffer_size binary_integer := 32000;
begin
if p_clob_in is null then
return null;
end if;
dbms_lob.CREATETEMPORARY(v_blob, true);
v_offset := 1;
FOR i IN 1..CEIL(dbms_lob.GETLENGTH(p_clob_in) / v_buffer_size)
loop
dbms_lob.READ(p_clob_in, v_buffer_size, v_offset, v_buffer_varchar);
v_buffer_raw := utl_encode.BASE64_DECODE(utl_raw.CAST_TO_RAW(v_buffer_varchar));*
dbms_lob.WRITEAPPEND(v_blob, utl_raw.LENGTH(v_buffer_raw), v_buffer_raw);
v_offset := v_offset v_buffer_size;+
end loop;
return v_blob;
end decode_base64;
The above procedure should work with files of any size (since there is a loop), but it only works when the PDF is smaller than 32 KB.Just a guess.
You may have additional CRLFs added when encoding.
Try this:
create or replace function replaceClob (opCLob CLOB,cpReplaceStr VARCHAR2,cpReplaceWith VARCHAR2) RETURN CLOB IS
cBuffer VARCHAR2 (32767);
nBuffer BINARY_INTEGER := 32767;
nStart PLS_INTEGER := 1;
nLen PLS_INTEGER;
oCRtn CLOB := EMPTY_CLOB;
BEGIN
DBMS_LOB.CreateTemporary(oCRtn,TRUE);
nLen := DBMS_LOB.GetLength(opCLob);
WHILE nStart < nLen
LOOP
DBMS_LOB.Read(opCLob, nBuffer, nStart, cBuffer);
IF cBuffer IS NOT NULL THEN
cBuffer := REPLACE(cBuffer, cpReplaceStr, cpReplaceWith);
DBMS_LOB.WriteAppend(oCRtn, LENGTH(cBuffer), cBuffer);
END IF;
nStart := nStart + nBuffer;
END LOOP;
RETURN oCRtn;
END;and then add to your code:
create or replace function decode_base64(p_clob_in in clob) return blob is
v_blob blob;
v_offset integer;
v_tem_clob clob;
v_buffer_varchar varchar2(32000);
v_buffer_raw raw(32000);
v_buffer_size binary_integer := 32000;
--v_buffer_size binary_integer := 3*1024;
begin
if p_clob_in is null then
return null;
end if;
-- Add this line
v_tem_clob := replaceClob(p_clob_in,UTL_TCP.CRLF,'');
dbms_lob.CREATETEMPORARY(v_blob, true);
v_offset := 1;
FOR i IN 1..CEIL(dbms_lob.GETLENGTH(v_tem_clob) / v_buffer_size) loop
dbms_lob.READ(v_tem_clob, v_buffer_size, v_offset, v_buffer_varchar);
v_buffer_raw := utl_encode.BASE64_DECODE(utl_raw.CAST_TO_RAW(v_buffer_varchar));
dbms_lob.WRITEAPPEND(v_blob, utl_raw.LENGTH(v_buffer_raw), v_buffer_raw);
v_offset := v_offset + v_buffer_size;
end loop;
return v_blob;
end decode_base64;Not tested.
HTH
Thomas -
Convert canvas.toDataURL('image/jpeg') to java.sql.Blob.
I am using oracle adf so I am able to action a backing bean from javascript and pass in parameters as a map. I pass in the canvas.toDataURL('image/jpeg') which I then try to decode in my bean. Using BASE64Decoder and the converting the bytearray to a file I can see the image is corrupted as I can't open the file thus converting the bytearray to blob is also a waste.
Has anyone any ideas on base64 encoding from canvas.toDataURL to file or Blob?Use Case:
A jsf page that enables a user to take photos using the HTML5 canvas feature - interact with webcam -, take photos and upload to profile
1. I have created the jsf page with the javascript below; this pops up as a dialog and works okay and onclick an upload image, triggers the snapImage javascript function below and sends the imgURL parameter to the serverside managedbean
<!-- java script-->
function snapImage(event){
var canvas = AdfPage.PAGE.findComponent('canvas');
AdfCustomEvent.queue(event.getSource(),"getCamImage",{imgURL:canvas.toDataURL('image/jpeg'),true);
event.cancel();
<!-- bean -->
public void getCamImage(ClientEvent ce){
String url=(String)ce.getAttributes().get("imgURL");
decodeBase64URLToBlob(url);
private BlobDomain decodeBaseB4URLToBlob(String url64){
BASE64Decoder de=new BASE64Decoder();
byte[] bytes=de.decode(url64);
File file=new File("abc.jpg");
InputStream in = new ByteArrayInputStream(bytes);
BufferedImage bImageFromConvert = ImageIO.read(in);
in.close();
ImageIO.write(bImageFromConvert, "jpg", file);
return createBlobDomainFromFile(file);
----problem---
Accessing the generated jpeg file shows the image is corrupted, probably missing bytes or encode/decoder issues.and the blob image after uploading to database is saved as a binary stream which ondownload doesnt render as an image or anything i know of.
Is there anyways of achieving the conversion without errors? -
I need to base64 binary encode a BLOB of up to 60k.
Basically I need a way to base64 binary encode a BLOB and output it to a text file.
I don't want to use UTL_ENCODE.BASE64_ENCODE(r raw) because breaking my BLOB into RAW size chunks, encoding each chunk and putting the encoded data back together again doesn't work, even if I strip the '=' character(s) off the end of all but the last chunk (they're there because of the way the data at the end of the encoded chunk falls for the bit count).
Basically I need a way to base64 binary encode a BLOB and output it to a text file.
The resultant encoded data will often exceed 32,000 characters.
Thanks in advance.
JohnThis may require a bit of tweaking for use as a Java stored procedure...
public class Base64Encoder {
/** Constructor
public Base64Encoder() {
public static String base64Encode(String s) {
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
Base64OutputStream out = new Base64OutputStream(bOut);
try {
out.write(s.getBytes());
out.flush();
} catch (IOException ioe) {
//Something to do if ioe occurs
return bOut.toString();
/* BASE64 encoding encodes 3 bytes into 4 characters.
|11111122|22223333|33444444|
Each set of 6 bits is encoded according to the
toBase64 map. If the number of input bytes is not
a multiple of 3, then the last group of 4 characters
is padded with one or two = signs. Each output line
is at most 76 characters.
class Base64OutputStream extends FilterOutputStream
{ public Base64OutputStream(OutputStream out)
{ super(out);
public void write(int c) throws IOException
{ inbuf[i] = c;
i++;
if (i == 3)
{ super.write(toBase64[(inbuf[0] & 0xFC) >> 2]);
super.write(toBase64[((inbuf[0] & 0x03) << 4) |
((inbuf[1] & 0xF0) >> 4)]);
super.write(toBase64[((inbuf[1] & 0x0F) << 2) |
((inbuf[2] & 0xC0) >> 6)]);
super.write(toBase64[inbuf[2] & 0x3F]);
col += 4;
i = 0;
if (col >= 76)
{ super.write('\n');
col = 0;
public void flush() throws IOException
{ if (i == 1)
{ super.write(toBase64[(inbuf[0] & 0xFC) >> 2]);
super.write(toBase64[(inbuf[0] & 0x03) << 4]);
super.write('=');
super.write('=');
else if (i == 2)
{ super.write(toBase64[(inbuf[0] & 0xFC) >> 2]);
super.write(toBase64[((inbuf[0] & 0x03) << 4) |
((inbuf[1] & 0xF0) >> 4)]);
super.write(toBase64[(inbuf[1] & 0x0F) << 2]);
super.write('=');
private static char[] toBase64 =
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
private int col = 0;
private int i = 0;
private int[] inbuf = new int[3];
} -
How to read a BLOB (base64 - stream) from XML-file in ORACLE10
ORACLE 10g
PL/SQL function
MY XML-file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<slo xmlns="http://www.example.org/detection">
<LekKey>1999_036371_509627</LekKey>
<HuiNum>46</HuiNum>
<Res></Res>
<InfLig>TEST STRUI AFGESTORVEN - PLAANSTRAAT 46</InfLig>
<XWGS>3.637028</XWGS>
<YWGS>50.962667</YWGS>
<Pei>EANDIS</Pei>
<DatPei>1999-11-30T10:17:36.000+01:00</DatPei>
<Kan> </Kan>
<Doc>UEsDBBQABgAIAAAAIQB5gHbnswEAAHcGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0VUtP20AQviP1P1h7rewNP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EAAAQAAAAAAAAAAAAAAAAAH8/CQBkb2NQcm9wcy9hcHAueG1sUEsFBgAAAAASABIA
pQQAALNCCQAAAA==</Doc>
</slo>
I have to write an PL/SQL function where I can read all the data in the XML-file (see attach).
In this XML there is a BLOB stored (base64 - stream -> that contains always a MSWORD document).
1) how can I extract this BLOB + the other data in the XML and save this data in a ORACLE table?
2) how can I decode this BLOB and save this MSWORD-document to a fileserver?First extract your data as CLOB (as it's character based)...
SQL> ed
Wrote file afiedt.buf
1 with t as (select xmltype('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 <slo xmlns="http://www.example.org/detection">
3 <LekKey>1999_036371_509627</LekKey>
4 <HuiNum>46</HuiNum>
5 <Res></Res>
6 <InfLig>TEST STRUI AFGESTORVEN - PLAANSTRAAT 46</InfLig>
7 <XWGS>3.637028</XWGS>
8 <YWGS>50.962667</YWGS>
9 <Pei>EANDIS</Pei>
10 <DatPei>1999-11-30T10:17:36.000+01:00</DatPei>
11 <Kan> </Kan>
12 <Doc>UEsDBBQABgAIAAAAIQB5gHbnswEAAHcGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAA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AYACAAAACEAp/3kQ44BAADeAgAAEQAAAAAAAAAAAAAAAACYOgkAZG9jUHJvcHMvY29yZS54bWxQSwECLQAUAAYACAAAACEAqchcqowAAADaAAAAEwAAAAAAAAAAAAAAAABdPQkAY3VzdG9tWG1sL2l0ZW0xLnhtbFBLAQItABQABgAIAAAAIQBgX/2ICwEAALoBAAAUAAAAAAAA
AAAAAAAAAEI+CQB3b3JkL3dlYlNldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQDQwaCR/gEAAGgEAAAQAAAAAAAAAAAAAAAAAH8/CQBkb2NQcm9wcy9hcHAueG1sUEsFBgAAAAASABIApQQAALNCCQAAAA==</Doc>
13 </slo>') as xml from dual)
14 --
15 -- end of test data
16 --
17 select x.*
18 from t
19 ,xmltable(xmlnamespaces(default 'http://www.example.org/detection'),
20 '/slo'
21 passing t.xml
22 columns lekkey varchar(30) path './LekKey'
23 ,doc clob path './Doc'
24* ) x
SQL> /
LEKKEY DOC
1999_036371_509627 UEsDBBQABgAIAAAAIQB5gHbnswEAAHcGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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YACAAAACEAp/3kQ44BAADeAgAA
EQAAAAAAAAAAAAAAAACYOgkAZG9jUHJvcHMvY29yZS54bWxQSwECLQAUAAYACAAAACEAqchcqowAAADa
AAAAEwAAAAAAAAAAAAAAAABdPQkAY3VzdG9tWG1sL2l0ZW0xLnhtbFBLAQItABQABgAIAAAAIQBgX/2I
CwEAALoBAAAUAAAAAAAAAAAAAAAAAEI+CQB3b3JkL3dlYlNldHRpbmdzLnhtbFBLAQItABQABgAIAAAA
IQDQwaCR/gEAAGgEAAAQAAAAAAAAAAAAAAAAAH8/CQBkb2NQcm9wcy9hcHAueG1sUEsFBgAAAAASABIA
pQQAALNCCQAAAA==
SQL>Then, you can convert the CLOB to a BLOB by doing your base64 decoding. -
hi, someone who can help me how to convert a blob oracle in base64.encode,
and viceverse.
please some idea
tanks
alexi saw a bit code about this convertions,
//one side
ResultSet r = ...........
BLOB b = (BLOB)r.getBlob('ICON');//BLOB is oracle type not Blob
byte[] base = b.getBytes();
Strgin res = Base64.encode(base);
//other side
String dec = datos;// data in base64
byte[] base = Base64.decode(dec.getBytes());
BLOB b = null;
b.setBytes(base);
is this code correct????
i tried to test but a have an error with
public static void BLOBToFile(BLOB datos,String path)
try
FileOutputStream fos=new FileOutputStream(path);
byte[] tempBin=new byte[8];
long cant=1;
while (cant <= datos.length())
tempBin=datos.getBytes(cant,Integer.MAX_VALUE);
cant = Integer.MAX_VALUE+1;
fos.write(tempBin);
fos.close();
catch(Exception e)
e.printStackTrace();
and the error is outOfMemory
how can i test my code??
alex -
Hi,
We have a table with two columns (Name varchar2, Picture Blob).
How do we get XML output containing rows from table, with Picture (blob column) being base64 encoded.
Note: I have tried using utl_encode.base64_encode, but getting error due to large size of Picture.
Thanks,
YjI am not sure what you finally want to accomplish (create a binary xml?), but to base64 encode a blob you could do it »stepwise«:
declare
bl blob; /* your picture blob */
bl_enc blob; /* encoded blob */
offset integer := 1;
amt integer := 20000;
begin
dbms_lob.createtemporary (bl_enc, false);
while dbms_lob.substr (bl, amt, offset) is not null
loop
dbms_lob.append (bl_enc, utl_encode.base64_encode (dbms_lob.substr (bl, amt, offset)));
offset := offset + amt;
end loop;
convert_to_xml(bl_enc);
dbms_lob.freetemporary (bl_enc);
end;
/ -
Report not generating with blob
SO I was trying to create a report to insert an image. I saw and followed the following resource: http://blogs.oracle.com/xmlpublisher/2006/05/inserting_blobs_into_your_repo.html
In the template builder for MSWord, where I grab the XML data containing the Base64 code for the image, the output is all there. - so yes the actual query grabs the base 64 version of the image, as per http://sergekoganovitsch.wordpress.com/2009/05/02/blob-base64-encoding/
Now the situation is there is a temporary table that stores all the fields, and the image, along with the apex session_id. So the report query looks like this:
SELECT
p.full_name
, blob_to_clob_base64(p_photo => p.photo) photo
FROM profiles_tmp p
WHERE p.session_id = :APP_SESSIONSo.. first to make sure it was all working properly, I created another report query specifying a specific session id in the where clause that I know contains a photo - all works fine. However, when I apply the layout to the query above, and test it - it comes out containing no pages. Even if I test it when going through the application where there would be a valid session id, still no pages.
I have tried changing :APP_SESSION to v('APP_SESSION') and to_number(:APP_SESSION) to no avail.
If i remove the image bit, and just have the field as <?PHOTO?> , it outputs the base64 contents fine - but obviously, I want the actual image in the report, not the base64 code.
IF i open the pdf file in a text editor, I get the following:
%PDF-1.4
1 0 obj
<<
/Type /Catalog
/Pages 3 0 R
>>
endobj
2 0 obj
<<
/Type /Info
/Producer (Oracle BI Publisher 10.1.3.4.1)
>>
endobj
3 0 obj
<<
/Type /Pages
/Kids [
/Count 0
>>
endobj
4 0 obj
<<
/ProcSet [ /PDF /Text ]
>>
endobj
xref
0 5
0000000000 65535 f
0000000010 00000 n
0000000065 00000 n
0000000147 00000 n
0000000208 00000 n
trailer
<<
/Size 5
/Root 1 0 R
/Info 2 0 R
/ID [<e45d94e9f08bf009170c54aabd4c051c><e45d94e9f08bf009170c54aabd4c051c>]
>>
startxref
258
%%EOF
<PRE>Servlet error: An exception occurred. The current application deployment descriptors do not allow for including it in this response. Please consult the application log for details.</PRE></BODY></HTML>The DBA enabled trace and I have that log file.. but don't really know what I am looking for :-/
It doesnt really make much sense to me, since when running it in the application there is a valid session id and it doesnt work. but if i explicitly specify the session id in the report query it does work.
Has anyone experienced said problem or can provide any useful guidance?
Thanks,
TrentFound out this was a limitation to do with apex <= 3.x .. see http://marcsewtz.blogspot.com/2008/06/one-question-about-pdf-printing-feature.html
-
Oracle error ORA-01461when trying to insert into an ORACLE BLOB field
I am getting Oracle error ‘ORA-01461: can bind a LONG value only for insert into a LONG column' when trying to insert into an ORACLE BLOB field. The error occurs when trying to insert a large BLOB (JPG), but does not occur when inserting a small (<1K) picture BLOB.(JPG). Any ideas?
BTW, when using a SQL Server datasource using the same code.... everything works with no problems.
ORACLE version is 11.2.0.1
The ORACLE datasource is JDBC using Oracle's JDBC driver ojdbc6.jar v11.2.0.1 (I also have tried ojdbc5.jar v11.2.0.1; ojdbc5.jar v11.2.0.4; and ojdbc6.jar v11.2.0.4 with the same error result.)
Here is my code:
<cfset file_mime = Lcase(Right(postedXMLRoot.objname.XmlText, 3))>
<cfif file_mime EQ 'jpg'><cfset file_mime = 'jpeg'></cfif>
<cfset file_mime = 'data:image/' & file_mime & ';base64,'>
<cfset image64 = ImageReadBase64("#file_mime##postedXMLRoot.objbase64.XmlText#")>
<cfset ramfile = "ram://" & postedXMLRoot.objname.XmlText>
<cfimage action="write" source="#image64#" destination="#ramfile#" overwrite="true">
<cffile action="readbinary" file="#ramfile#" variable="image_bin">
<cffile action="delete" file="#ramfile#">
<cfquery name="InsertImage" datasource="#datasource#">
INSERT INTO test_images
image_blob
SELECT
<cfqueryparam value="#image_bin#" cfsqltype="CF_SQL_BLOB">
FROM dual
</cfquery>Can't you use "alter index <shema.spatial_index_name> rebuild ONLINE" ? Thanks. I could switch to "rebuild ONLINE" and see if that helps. Are there any potential adverse effects going forward, e.g. significantly longer rebuild than not using the ONLINE keyword, etc? Also wondering if spatial index operations (index type = DOMAIN) obey all the typical things you'd expect with "regular" indexes, e.g. B-TREE, etc.
-
Rendering a dynamic image(blob) in a BI Publisher Report via an RTF templat
Been working on this for a while and now at a dead end hoping the experts can direct me to try something new. There is lots in the forums on blobs and displaying in reports and from it all I have gleaned that I need to encode the blob in Base64 and then use this code.
<fo:instream-foreign-object content type="image/jpg">
<xsl:value-of select="IMAGE_ELEMENT"/>
</fo:instream-foreign-object>
I use this function to encode a 9KB jpeg into a clob (and my jpegs will be less then 32K.
function encode_base64(p_blob_in in blob) return clob is
v_clob clob;
v_result clob;
v_offset integer;
v_chunk_size binary_integer := (48 / 4) * 3;
v_buffer_varchar varchar2(48);
v_buffer_raw raw(48);
begin
if p_blob_in is null then
return null;
end if;
dbms_lob.createtemporary(v_clob, true);
v_offset := 1;
for i in 1 .. ceil(dbms_lob.getlength(p_blob_in) / v_chunk_size) loop
dbms_lob.read(p_blob_in, v_chunk_size, v_offset, v_buffer_raw);
v_buffer_raw := utl_encode.base64_encode(v_buffer_raw);
v_buffer_varchar := utl_raw.cast_to_varchar2(v_buffer_raw);
dbms_lob.writeappend(v_clob, length(v_buffer_varchar), v_buffer_varchar);
v_offset := v_offset + v_chunk_size;
end loop;
v_result := v_clob;
dbms_lob.freetemporary(v_clob);
return v_result;
end encode_base64;
The xml is simple:
<?xml version="1.0" encoding="UTF-8"?>
<ROWSET>
<ROW>
<IMAGE_NAME>Test</IMAGE_NAME>
<IMAGE_MIME_TYPE> image/jpeg </IMAGE_MIME_TYPE>
<IMAGE_ELEMENT>…lots lines of encoded data… </ IMAGE_ELEMENT >
</ROW>
</ROWSET>
Then when I put all together using BI Publisher Desktop 11.1.1.6 in an rtf template and preview the pdf, the preview fails with a long message ( can provide the whole thing if requested) but starting with:
java.lang.ArrayIndexOutOfBoundsException: 0
at oracle.xdo.common.image.ImageReader.checkFormat(ImageReader.java:130)
at oracle.xdo.common.image.ImageReader.analyze
I suspect the base64 encoding may be the problem but I am out of my realm in trying to debug this. Any help would be most appreciated…sorry for the length of this.I thank you again for continuing to try to help me. However, I regret to say that this function does not work. The same error results (see below). It is hard to believe that this cannot be done with APEX and BI Publisher. I would think that other APEX users have the need to display images and do not have the E-Business Suite.
What I am doing is very straightforward....a small jpeg stored as a blob in an Oracle table that needs to be dynamically displayed from a report in APEX----created with BI Publisher and an rtf template.
If you have any other ideas, please send them..your help is appreciated.
Java.lang.ArrayIndexOutOfBoundsException: 0
at oracle.xdo.common.image.ImageReader.checkFormat(ImageReader.java:130)
at oracle.xdo.common.image.ImageReader.analyze(ImageReader.java:314)
at oracle.xdo.common.image.ImageReader.load(ImageReader.java:510)
at oracle.xdo.generator.pdf.PDFGenerator.createPDFImageReference(PDFGenerator.java:3261)
at oracle.xdo.generator.pdf.PDFGenerator.getImage(PDFGenerator.java:3399)
at oracle.xdo.generator.pdf.PDFGenerator.getImage(PDFGenerator.java:3388)
at oracle.xdo.generator.ProxyStreamGenerator.getImage(ProxyStreamGenerator.java:121)
at oracle.xdo.template.fo.area.AreaTree.getImage(AreaTree.java:779)
at oracle.xdo.template.fo.area.InstreamForeignObjectArea.loadImage(InstreamForeignObjectArea.java:82)
at oracle.xdo.template.fo.area.InstreamForeignObjectArea.init(InstreamForeignObjectArea.java:151)
at oracle.xdo.template.fo.area.GraphicArea.<init>(GraphicArea.java:80)
at oracle.xdo.template.fo.area.InstreamForeignObjectArea.<init>(InstreamForeignObjectArea.java:51)
at oracle.xdo.template.fo.elements.FOInstreamForeignObject.doLayout(FOInstreamForeignObject.java:134)
at oracle.xdo.template.fo.elements.FOInline.doLayout(FOInline.java:147)
at oracle.xdo.template.fo.elements.FOInline.doLayout(FOInline.java:83)
at oracle.xdo.template.fo.elements.FOBlock.doLayout(FOBlock.java:330)
at oracle.xdo.template.fo.elements.FOBlock.doLayout(FOBlock.java:226)
at oracle.xdo.template.fo.elements.FOBlock.doLayout(FOBlock.java:140)
at oracle.xdo.template.fo.elements.FOFlow.doLayout(FOFlow.java:84)
at oracle.xdo.template.fo.elements.FormattingEngine.startLayout(FormattingEngine.java:250)
at oracle.xdo.template.fo.elements.FormattingEngine.run(FormattingEngine.java:141)
at oracle.xdo.template.fo.FOHandler.endElement(FOHandler.java:720)
at oracle.xdo.common.xml.XSLTHandler$EEEntry.sendEvent(XSLTHandler.java:595)
at oracle.xdo.common.xml.XSLTMerger.startElement(XSLTMerger.java:51)
at oracle.xdo11g.parser.v2.XMLContentHandler.startElement(XMLContentHandler.java:182)
at oracle.xdo11g.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1322)
at oracle.xdo11g.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:366)
at oracle.xdo11g.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:312)
at oracle.xdo11g.parser.v2.XMLParser.parse(XMLParser.java:218)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at oracle.xdo.common.xml.XDOSAXParser.invokeParse(XDOSAXParser.java:166)
at oracle.xdo.common.xml.XDOSAXParser.parse(XDOSAXParser.java:122)
at oracle.xdo.template.fo.FOProcessingEngine.process(FOProcessingEngine.java:407)
at oracle.xdo.template.FOProcessor.generate(FOProcessor.java:1218)
at RTF2PDF2.runRTFto(RTF2PDF2.java:473)
at RTF2PDF2.runXDO(RTF2PDF2.java:337)
at RTF2PDF2.main(RTF2PDF2.java:230) -
Help with displaying BLOBs in OBIEE 11g
I am trying to get OBIEE 11g to display photographs in an Analysis report. I know BLOB fields are not supported, and I have been reading posts on this board and following examples on internet sites that try to get round this problem. But, try as I might, I cannot get those pesky photos to display.
Below are all the steps I have followed. Sorry that there is a lot to read, but I was hoping that somebody has been successful in doing this, and may spot something in one of my steps that I am doing wrong.
ORACLE TRANSACTIONAL SOURCE_
Table : EMPL_PHOTO
Fields:
USN VARCHAR2(11) ( Unique Key )
EMPLOYEE_PHOTO BLOB ( I think the photos are stored as 'png' )
ORACLE WAREHOUSE SOURCE_
Table : D_PERSON_PHOTO_LKUP
Fields :
PERSON_KEY NUMBER(38,0) ( Primary Key - Surrogate )
USN VARCHAR2(11)
PHOTO CLOB
BLOB to CLOB conversion.
I used this function :
create or replace function blob_to_clob_base64(p_data in blob)
return clob
is
l_bufsize integer := 16386;
l_buffer raw(16386);
l_offset integer default 1;
l_result clob;
begin
dbms_lob.createtemporary(l_result, false, dbms_lob.call);
loop
begin
dbms_lob.read(p_data, l_bufsize, l_offset, l_buffer);
exception
when no_data_found then
exit;
end;
l_offset := l_offset + l_bufsize;
dbms_lob.append(l_result, to_clob(utl_raw.cast_to_varchar2(utl_encode.base64_encode(l_buffer))));
end loop;
return l_result;
end;
select usn, employee_photo ,
BLOB_TO_CLOB_BASE64(employee_photo)
from empl_photo
IN OBIEE ADMINISTRATION TOOL_
*1) Physical Layer*
Added D_PERSON_PHOTO_LKUP from Connection Pool
Left it as 'Cachable'
Didn't join it to any tables
Changed field PHOTO to a 'LONGVARCHAR' length 100000
Set USN as the Key ( not the surrogate key )
*2) BMM Layer*
Dragged D_PERSON_PHOTO_LKUP across.
Renamed it to 'LkUp - Photo'
Ticked the 'lookup table' box
Removed the surrogate key
Kept USN as the Primary key
The icon shows it similar to a Fact table, with a yellow key and green arrow.
On Dimension table D_PERSON_DETAILS (Dim - P01 - Person Details) added a new logical column
Called it 'Photo'
Changed the column source to be derived from an expression.
Set the expression to be :
Lookup(DENSE
"People"."LkUp - Photo"."PHOTO",
"People"."Dim - P01 - Person Details"."USN" )
Icon now shows an 'fx' against it.
Note: This table also had it Surrogate key removed, and USN setting as primary key.
*3) Presentation Layer*
Dragged the new Photo field across.
Saved Repository file, uploaded, and restarted server.
ONLINE OBIEE_
Created a new Analysis.
Selected USN from 'Person Details'
Selected Photo from 'Person Details'
Selected a measure from the Fact table
Under column properties of Photo ( data format ) :
- Ticked 'Override Default Data Format' box
- Set to Image URL
- Custom text format changed to : @[html]"<img alt="" src=""@H"">"
Under column properties of Photo ( edit formula ) :
- Changed to : 'data:image/png;base64,'||"Person Details"."Photo"
The Advanced tab shows the sql as :
SELECT
0 s_0,
"People"."Person Details"."USN" s_1,
'data:image/png;base64,'||"People"."Person Details"."Photo" s_2,
"People"."MEASURE"."Count" s_3
FROM "People"
ORDER BY 1, 2 ASC NULLS LAST, 3 ASC NULLS LAST
FETCH FIRST 65001 ROWS ONLY
Going into the 'results' tab, get error message:
+State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 17001] Oracle Error code: 932, message: ORA-00932: inconsistent datatypes: expected - got CLOB at OCI call OCIStmtExecute. [nQSError: 17010] SQL statement preparation failed. (HY000)+
It doesn't seem to be using the Lookup table, but can't work out at which step I have gone wrong.
Any help would be appreciated.
ThanksThanks, yes I followed http://docs.oracle.com/cd/E28280_01/bi.1111/e10540/busmodlayer.htm#BGBDBDHI, but when I get to the part of setting the LOOKUP function on th Physical source, only ONE physical source is displayed. I need TWO sources ( The Employee Table, and the Photo LookUp.
I have raised this as an error with Oracle. We are now on OBIEE 11.1.1.7, but Oracle say BLOBS are still not supported in that release. It will be fixed in 11.1.1.8 and it will be backported into 11.1.1.6.11
In the meantime we have abandoned showing Photo's in any of our reports. -
Problem with My Base64 Encoding CLOB Routine.
I have written a program which reads an xml file into the database
and makes it Base64encoded.
This needs to work on 10g and above
If the read length specified in the code below is greater than the length of the xml_file, then I get the expected result(output).
However if the read length is less than the length of the file, then I get a lot of '==' in the file and as a result, incorrect encoding which means that the file will not be readable through the application.
I'm pretty sure I'm reading the blob lengths correctly, and the problem is somehow related to the base64 encoding.Any help appreciated
[create or replace profile_dir as &profile_dir;
create global temporary table load_xml
(profile_text clob)
on commit delete rows;
create or replace
procedure encode_xml_clobs(p_file_in in varchar2,
p_clob_out out nocopy clob )
as
pragma autonomous_transaction;
dest_clob CLOB;
src_clob BFILE := BFILENAME('PROFILE_DIR', p_file_in);
dst_offset number := 1 ;
src_offset number := 1 ;
lang_ctx number := DBMS_LOB.DEFAULT_LANG_CTX;
warning number;
-- processing declarations for encoding base64 --
v_xml_string varchar2(32767);
v_string varchar2(32767);
v_start_pos number := 0;
v_read_length number := 1000;
v_final_start_pos number;
v_clob_length number;
type clob_array_type is table of clob index by binary_integer;
clob_array clob_array_type;
v_index number :=0;
-- Declarations for converting base64encoded string to a clob
v_encoded_length number;
v_temp_clob clob;
BEGIN
-- THE FOLLOWING BLOCK OF CODE WILL ATTEMPT TO INSERT / WRITE THE CONTENTS
-- OF AN XML FILE TO A CLOB COLUMN. IN THIS CASE, WE WILL USE THE NEW
-- DBMS_LOB.LoadCLOBFromFile() API WHICH *DOES* SUPPORT MULTI-BYTE
-- CHARACTER SET DATA.
-- load_xml should be a Global temporary table with on commit delete rows
INSERT INTO load_xml(profile_text)
VALUES( empty_clob())
RETURNING profile_text INTO dest_clob;
-- OPENING THE SOURCE BFILE IS MANDATORY
DBMS_LOB.OPEN(src_clob, DBMS_LOB.LOB_READONLY);
DBMS_LOB.LoadCLOBFromFile(
DEST_LOB => dest_clob
, SRC_BFILE => src_clob
, AMOUNT => DBMS_LOB.GETLENGTH(src_clob)
, DEST_OFFSET => dst_offset
, SRC_OFFSET => src_offset
, BFILE_CSID => DBMS_LOB.DEFAULT_CSID
, LANG_CONTEXT => lang_ctx
, WARNING => warning
DBMS_LOB.CLOSE(src_clob);
-- DBMS_OUTPUT.PUT_LINE('Loaded XML File using DBMS_LOB.LoadCLOBFromFile: (ID=1');
-- file now successfully loaded
select dbms_lob.GETLENGTH(profile_text)
into v_clob_length
from load_xml;
-- File now loaded in temporary table
-- we now need to take the clob , convert it to varchar2
v_read_length :=64;
v_xml_string := '';
while v_start_pos <= v_clob_length
loop
v_index := v_index + 1;
v_string := '';
--dbms_output.put_line('Start_pos=>'||(v_start_pos+1)||' Read Length=>'||v_read_length);
--encode base64
select utl_raw.cast_to_varchar2(
utl_encode.base64_encode(
utl_raw.cast_to_raw(dbms_lob.substr(profile_text,least(v_read_length,v_clob_length-v_start_pos),v_start_pos+1))
into v_string
from load_xml;
--dbms_output.put_line(v_string);
v_start_pos := v_start_pos+v_read_length;
clob_array(v_index) := v_string;
end loop;
p_clob_out := clob_array(1);
for i in 2 .. v_index
loop
dbms_lob.append(p_clob_out,clob_array(i));
end loop;
commit;
END;Base64 encoding encodes every 3 bytes of input data into 4 bytes of output data. It uses equal signs to indicate nodata and only at the end of the encoded sequence. Try chaning your v_read_length parameter to a multiple of 3 e.g. 960 or 1008 instead of the current 1000. I'm using multiples of 48 because the utl_encode.base64_encode function adds a linebreak for every 48 bytes of input data (64 bytes of output). If you use a value that's not divisible by 48 you will still get a legitimate encoding as long as it's divisible by 3, but you will get some lines longer than others when you append them together.
-
PDF Image printing, base64encoded blobs
Hi guys!
I'm trying to extract images from a table (blob) and put it in a PDF-report, through ApEx.
After reading this blogpost about image-blobs in reports(http://blogs.oracle.com/xmlpublisher/2006/05/05#a34) I thought "this was interesting, this is exactly what my customer want". So, I made a function to dump the blob as base64-data (found some codesnippets here and there..):
function BLOB2CLOBASE64( p_blob IN BLOB ) RETURN CLOB
IS
pos PLS_INTEGER := 1;
buffer VARCHAR2( 32767 );
res CLOB;
lob_len INTEGER := DBMS_LOB.getLength( p_blob );
BEGIN
DBMS_LOB.createTemporary( res, TRUE );
DBMS_LOB.OPEN( res, DBMS_LOB.LOB_ReadWrite );
LOOP
buffer := utl_raw.cast_to_varchar2(utl_encode.base64_encode( DBMS_LOB.SUBSTR( p_blob, 32000, pos )));
IF LENGTH( buffer ) > 0 THEN
DBMS_LOB.writeAppend( res, LENGTH( buffer ), buffer );
END IF;
pos := pos + 32000;
EXIT WHEN pos > lob_len;
END LOOP;
RETURN res; -- res is OPEN here
END BLOB2CLOBASE64;
Works great! I get the imagefile dumped as base64.
So, time to try this out. I make a Report query in ApEx, and
do a
"select blob2clobase64(image_file) IMAGE from testphotos"
XML gets dumped, and I can load it into my BI Publisher Desktop/Word. I do like it's done in the blogpost above, and enter the following for the IMAGE-field:
<fo:instream-foreign-object content-type="image/jpg">
<xsl:value-of select="IMAGE"/>
</fo:instream-foreign-object>
(In the examplecode from the above blog-link; see how this code is entered in the Help-section when you do "Properties" for the field).
Ok, here goes, let's give it a try: Preview -> PDF and out pops two wonderful pictures that's in my table 'testphotos '. Hooray!
I save the template, and upload it to ApEx through the Create Report Query-wizard. Go to the last page. Press "Test query". Out comes: A PDF-file with all the text from the template, but no pictures.
What have gone wrong? Any inputs?
Thanks for now,
Vidar
PS: Size of the 2 images together is 10-15kb max.
PS2: Application Express 3.0.0.00.20
Message was edited by:
Vidar
: added apex versioninfoHello
Just wanted to give this a bump, as I made this thread just before the weekend. It's dropped quite long, so thought I'd bring it upfront again now that people might be back.
Regards,
Vidar
Maybe you are looking for
-
I have never gotten this error before. I also tried restarting my computer but it says the same thing. I had no problem copying my documents or photos. Please help!
-
Error when using LOV wildcard(%) in custom web ADI
Hello, I'm getting the following error on a custom Web ADI integrator. There are a number of LOVs on the form, and they're all working fine except one. The LOV is populated correctly, however, once the wildcard (%) search is used, the following error
-
Zen Xtra: USB Cable length
Does anyone know what the cable length is? Because just recently, a friend of mine bought me one, and I needed to get a PCI to USB card because my PC only supported USB .. But, I want the cable to reach up to the top of my tower at least. Thanks.
-
Hi friends, IDOC and RFC are sap related.but idoc is in abap stack rfc is
1)IDOC and RFC are sap related.but idoc is in abap stack rfc is in java stack.what is difference between two.?
-
HBRs migrating from EPM 11.1.1.4 to 11.1.2.2.
Hi All, I am facing an issue migrating my HBR from 11.1.1.4 to calc manager in 11.1.2.2. I've migrating my HBRs from 11.1.1.4 to 11.1.2.1 version and exported them to XML file checking the option "For Cacl Mgr" at EAS.