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 first published in August 2006

Dig deeper on Using Oracle PL-SQL

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

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.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close