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 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.

    Requires Free Membership to View

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

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.