I might be taking the wrong approach or not understanding correctly the base64 algorithm.
I have a REST service that asks for a JSON with various parameters,
{
"credentials":{...}
, "content":"BASE64"
, ...more
}
The content key contains a string which represents a base64 encoded of an invoice.
In love with the simplicity of php I only do this
$xml_string = '<?xml version="1.0" encoding="UTF-8"?>...more xml stuff';
$content = base64_encode($xml_string);
Et Voilà I have my content encoded plain an simple, ready to be sent to the third party.
Migrating to Oracle I did this
declare
xml_string varchar2(4000):= '<?xml version="1.0" encoding="UTF-8"?>...more xml stuff';
b64 varchar2(4000);
begin
b64 := utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(xml_string)));
end;
And it works, easy right? Well no with oracle nothing is easy, it has to be a pain in the ass.
The invoice XML may have a lot of concepts and can grow quite big so it's reasonable to assume that varchar2(4000) will not be enough eventually.
So the xml_string
now is a clob
to accommodate bigger strings, easy no?
again no I did this without success:
declare
xml_string clob:= '<?xml version="1.0" encoding="UTF-8"?>...more xml stuff';
b64 clob;
begin
b64:=to_clob(utl_encode.base64_encode(utl_raw.cast_to_raw(xml_string));
end;
but it only gives me a garbage string once decoded.
Is there a function (can be user made) that makes a simple base64encode of a CLOB string.
I have only found functions for blobs (images and binary files). And this one that receives a CLOB and gives a CLOB (perfection ehh?) well does not work http://bitwiseeloquence.blogspot.mx/2011/07/converting-to-and-from-base-64-clob-in.html