I have written function send to email using pl/sql. i need to send other data with blob file as json format. the procedure code as below.
create or replace FUNCTION EmailProc (
p_to IN VARCHAR2,
p_subject IN VARCHAR2,
p_body IN VARCHAR2,
p_attachement IN BLOB DEFAULT NULL
) RETURN NUMBER AS
req utl_http.req;
res utl_http.resp;
url VARCHAR2(4000) := 'http://192.168.168.01:8080/api/Myemails';
name VARCHAR2(4000);
buffer VARCHAR2(32767);
content CLOB:= '{
"to": "'|| p_to ||'",
"subject": "'|| p_subject ||'",
"body": "'|| p_body ||'",
"Attahement": '|| p_attachement ||'
}';
emailresult NUMBER := 0;
BEGIN
BEGIN
dbms_output.put_line(content);
req := utl_http.begin_request(url,'POST',' HTTP/1.1');
utl_http.set_header(req,'user-agent','mozilla/4.0');
utl_http.set_header(req,'content-type','application/json; charset=UTF-8');
utl_http.set_header(
req,
'Content-Length',
DBMS_LOB.getlength (content)
);
utl_http.set_body_charset(req, 'UTF-8');
utl_http.WRITE_RAW(r => req, data => UTL_RAW.CAST_TO_RAW(content));
res := utl_http.get_response(req);
utl_http.read_line(res,buffer,true);
dbms_output.put_line(buffer);
IF
buffer = '"000"'
THEN
dbms_output.put_line(buffer);
emailresult := 1;
END IF;
utl_http.end_response(res);
RETURN emailresult;
EXCEPTION
WHEN OTHERS THEN
utl_http.end_response(res);
dbms_output.put_line('exception block in email function');
RETURN 0;
END;
END EmailProc;
Above code i used "Attahement": '|| p_attachement ||' but it is cannot be implemented like this. i need to some advice, how to implement blob file as binary stream inside json format.
My Model include attachment property
public byte[] Attahement { get; set; }
My Web API as below
public void Myemails(EmailModel emailModel)
i was able to bind all the data except attachment. any one can give me a advice how do i parse attachment inside json object as binary stream?