Q

Parsing, converting and loading image with XML

I have to parse an image from XML. The image is in base64 encoded form. I have to parse the image, convert it to binary and load it in a blob in an Oracle database.

I have to parse an image from XML. The image is in base64 encoded form. I have to parse the image, convert it to binary and load it in a blob in an Oracle database. I have two questions:
  1. Can I use the following to convert from base64 to binary:
    utl_encode.base64_decode(r IN raw) return raw;
    
  2. If so, what will be the datatype of the variable where I get the returned value (which is raw)? The max size that is allowed for a raw in PL/SQL is 32767 and the image size may be more than that.
I found the below procedure at Metalink in Note: 357385.1 I hope this helps:
PROCEDURE attach_base64(conn IN OUT NOCOPY 
  utl_smtp.connection,data IN RAW,mime_type IN VARCHAR2 DEFAULT 
  'application/octet',inline IN BOOLEAN DEFAULT TRUE,filename 
  IN VARCHAR2 DEFAULT NULL,last IN BOOLEAN DEFAULT FALSE) IS
i PLS_INTEGER;
len PLS_INTEGER;
BEGIN
begin_attachment(conn, mime_type, inline, filename, 'base64');
i := 1;
len := utl_raw.length(data);
WHILE (i < len) LOOP
IF (i + MAX_BASE64_LINE_WIDTH < len) THEN
utl_smtp.write_raw_data(conn,
utl_encode.base64_encode(utl_raw.substr(data, i,
MAX_BASE64_LINE_WIDTH)));
ELSE
utl_smtp.write_raw_data(conn,
utl_encode.base64_encode(utl_raw.substr(data, i)));
END IF;
utl_smtp.write_data(conn, utl_tcp.CRLF);
i := i + MAX_BASE64_LINE_WIDTH;
END LOOP;
end_attachment(conn, last);
END;
This was last published in August 2006

Dig Deeper on Using Oracle PL-SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close