Is it possible to convert a blob type image stored in a database table to png? I need to send the image as png to a website using REST, but if I send the database blob item(converted to base64 before sending), the data is getting sent, but the image won't load up when I click on it to show. Could anyone give me a tip on how to do this?
Thanks in advance, Tamas
Edit1: here's the whole code I'm using
The first request uploads the file to the website, and sends back a token with which I can then attach the file to the second request. As you can see, both of the request bodys state that the content type is image/png, so I don't exactly understand what can be the problem.
create or replace procedure publish_error_tickets(p_priority_id varchar2, p_description varchar2)
is
req1 utl_http.req;
res1 utl_http.resp;
req2 utl_http.req;
res2 utl_http.resp;
lc_entire_message clob;
l_attachment clob;
url1 varchar2(4000) := 'http://revprox.local/inno-dev.cloudapp.net/redmine/uploads.json';
url2 varchar2(4000) := 'http://revprox.local/inno-dev.cloudapp.net/redmine/projects/support-interface-teszt/issues.json';
name varchar2(4000);
token varchar2(4000);
buffer varchar2(4000);
content varchar2(4000);
p_id number;
p_image blob;
l_request_body clob;
l_request_body_length number;
l_offset number := 1;
l_amount number := 2000;
l_buffer varchar2(4000);
begin
select max(id) into p_id from t_tkt_temp_images;
select image into p_image from t_tkt_temp_images where id = p_id;
l_request_body := apex_web_service.blob2clobbase64(p_image);
l_request_body_length := length(l_request_body);
req1 := utl_http.begin_request(url1, 'POST',' HTTP/1.1');
utl_http.set_header(req1, 'User-Agent', 'mozilla/4.0');
utl_http.set_header(req1, 'Content-Type', 'application/octet-stream');
utl_http.set_header(req1, 'Content-Length', l_request_body_length);
utl_http.set_header(req1, 'Content-Disposition', 'attachment; filename="file.png"');
utl_http.set_header(req1, 'X-Redmine-API-Key', '0asddq3t23w4esdf');
while l_offset < l_request_body_length loop
dbms_lob.read(l_request_body, l_amount, l_offset, l_buffer);
utl_http.write_text(req1, l_buffer);
l_offset := l_offset + l_amount;
end loop;
res1 := utl_http.get_response(req1);
begin
loop
utl_http.read_text(res1, buffer);
lc_entire_message := buffer;
end loop;
utl_http.end_response(res1);
exception
when utl_http.end_of_body
then
utl_http.end_response(res1);
end;
apex_json.parse(lc_entire_message);
token := apex_json.get_varchar2(p_path => 'upload.token');
content :=
'{
"issue": {
"subject": "Hibajegy",
"priority_id": '|| 1 ||',
"description": "asd",
"uploads": [
{"token": "'||token||'", "filename": "file.png", "content_type": "image/png"}
]
}
}';
req2 := utl_http.begin_request(url2, 'POST',' HTTP/1.1');
utl_http.set_header(req2, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req2, 'content-type', 'application/json');
utl_http.set_header(req2, 'Content-Length', length(content));
utl_http.set_header(req2, 'X-Redmine-API-Key', '0asddq3t23w4esdf');
utl_http.write_text(req2, content);
res2 := utl_http.get_response(req2);
begin
loop
utl_http.read_line(res2, buffer);
end loop;
utl_http.end_response(res2);
exception
when utl_http.end_of_body
then
utl_http.end_response(res2);
end;
end publish_error_tickets;