是否可以将存储在数据库表中的blob类型图像转换为png?我需要使用REST将图像作为png发送到网站,但是如果我发送数据库blob项目(在发送之前转换为base64),数据将被发送,但是当我点击它时图像将不会加载节目。谁能给我一个如何做到这一点的小费?
提前致谢, 的Tamas
Edit1:这是我正在使用的整个代码
第一个请求将文件上传到网站,并发回一个令牌,然后我可以将该文件附加到第二个请求。 正如您所看到的,两个请求机构都声明内容类型是image / png,因此我并不完全理解可能出现的问题。
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;