Oracle apex 多部分/表单数据请求传递BLOB文件

Oracle apex 多部分/表单数据请求传递BLOB文件,oracle-apex,Oracle Apex,我想把BLOB文件传递给JIRA。我怎么能做到?我试过: DECLARE l_start TIMESTAMP; l_duration NUMERIC; l_result VARCHAR2(32767); p_array APEX_APPLICATION_GLOBAL.VC_ARR2; v_login VARCHAR2(100); v_password VARCHAR2(100); f_body_blob BLOB; f_r

我想把BLOB文件传递给JIRA。我怎么能做到?我试过:

DECLARE
    l_start TIMESTAMP;
    l_duration NUMERIC;

    l_result VARCHAR2(32767);  
    p_array APEX_APPLICATION_GLOBAL.VC_ARR2;

    v_login VARCHAR2(100);
    v_password VARCHAR2(100);

    f_body_blob BLOB;
    f_response CLOB;

    f_body_clob CLOB;

BEGIN  
    v_login := 'user';
    v_password := 'psw';

    SELECT PHOTO INTO f_body_blob FROM LEAN5S_PHOTO WHERE ID = 189;

    apex_web_service.g_request_headers.delete;
    apex_web_service.g_request_headers(1).name := 'Content-Type';
    apex_web_service.g_request_headers(1).value := 'multipart/form-data';
    apex_web_service.g_request_headers(2).name := 'X-Atlassian-Token';
    apex_web_service.g_request_headers(2).value := 'no-check';
    apex_web_service.g_request_headers(3).name := 'file';
    apex_web_service.g_request_headers(3).value := 'hand-sanitizer.png';

    l_start := systimestamp;
    f_response := apex_web_service.make_rest_request(p_url => 'http://site/rest/api/2/issue/key/attachments',  
                                                     p_http_method => 'POST',
                                                     p_body_blob => f_body_blob,
                                                     p_username => v_login,
                                                     p_password => v_password
    );
    l_duration := round(extract(second from systimestamp - l_start) * 1000);

    dbms_output.put_line(apex_web_service.g_status_code || ' ' || f_response);
END;
但我收到请求错误(500),文件未上传:

500 500org.apache.commons.fileupload.FileUploadException: 请求被拒绝,因为未创建多部分边界 foundjava.lang.RuntimeException: org.apache.commons.fileupload.FileUploadException:请求为 已拒绝,因为未找到多部分边界

我的同事尝试了另一种变体:

DECLARE
  p_url          VARCHAR2(255) := 'http://site/rest/api/2/issue/key/attachments';
  utl_req        utl_http.req;
  utl_resp       utl_http.resp;
  req_length     BINARY_INTEGER;
  response_body  VARCHAR2(32767);
  p_request_body clob;
  l_newline      VARCHAR2(50) := chr(13) || chr(10);
  lco_boundary CONSTANT VARCHAR2(30) := 'AaB03x';
  buffer raw(32767);
  amount number(15) := 32767;
  offset number(15) := 1;

  l_attachment blob;
  l_file_name  VARCHAR2(255);
  l_mime_type  VARCHAR2(255);
  
  l_response_header_name varchar2(256);
  l_response_header_value varchar2(1024);
  l_response_body varchar2(32767);

  lang_context integer;
  warning      varchar2(1000);
  blb          blob;

  tmp_blob blob default EMPTY_BLOB();

  dest_offset integer := 1;
  src_offset  integer := 1;
BEGIN
    SELECT PHOTO, FILENAME, MIMETYPE
        INTO l_attachment, l_file_name, l_mime_type
        FROM LEAN5S_PHOTO
        WHERE ID = 156;

  p_request_body := l_newline || '--' || lco_boundary || l_newline ||
                    'Content-Disposition: form-data; name="file"; filename="' ||
                    l_file_name || '"' || l_newline || 'Content-Type: ' ||
                    l_mime_type || l_newline ||
                    'Content-Transfer-Encoding: binary' || l_newline ||
                    l_newline ||
                    apex_web_service.blob2clobbase64(l_attachment) ||
                    l_newline || '--' || lco_boundary || '--';

  dbms_lob.createtemporary(blb, FALSE);
  dest_offset  := 1;
  src_offset   := 1;
  lang_context := 0;
  dbms_lob.converttoblob(blb,
                         p_request_body,
                         dbms_lob.getlength(p_request_body),
                         dest_offset,
                         src_offset,
                         0,
                         lang_context,
                         warning);
  dbms_lob.append(blb, l_attachment);
  req_length := dbms_lob.getlength(blb);

  utl_req := utl_http.begin_request(url          => p_url,
                                    method       => 'POST',
                                    http_version => 'HTTP/1.1');
  utl_http.set_authentication(utl_req, 'user', 'psw', 'Basic');                                  
  utl_http.set_header(utl_req, 'X-Atlassian-Token', 'no-check');
  utl_http.set_header(utl_req, 'User-Agent', 'Mozilla/4.0');
  utl_http.set_header(utl_req,
                      'Content-Type',
                      'multipart/form-data; boundary="' || lco_boundary || '"');
  dbms_output.put_line(req_length);

  IF req_length <= 32767 THEN
    utl_http.set_header(utl_req, 'Content-Length', req_length);
    utl_http.write_raw(utl_req, blb);
  ELSIF req_length > 32767 THEN
    utl_http.set_header(utl_req, 'Transfer-Encoding', 'chunked');
    WHILE (offset < req_length) LOOP
      dbms_lob.read(blb, amount, offset, buffer);
      utl_http.write_raw(utl_req, buffer);
      offset := offset + amount;
    END LOOP;
  END IF;

  utl_resp := utl_http.get_response(utl_req);
  
  dbms_output.put_line('Response> Status Code: ' || utl_resp.status_code);
  
  for i in 1 .. utl_http.get_header_count(utl_resp) loop
    utl_http.get_header(utl_resp, i, l_response_header_name, l_response_header_value);
    dbms_output.put_line('Response> ' || l_response_header_name || ': ' || l_response_header_value);
  end loop;

  utl_http.read_text(utl_resp, l_response_body, 32767);
  
  --utl_http.read_raw(utl_resp, response_body, 32767);
  
  dbms_output.put_line('Response body>');
  dbms_output.put_line(l_response_body);
  
  utl_http.end_response(utl_resp);

EXCEPTION
  WHEN UTL_HTTP.TOO_MANY_REQUESTS THEN
    utl_http.END_RESPONSE(utl_resp);
  
END;
声明
p_url VARCHAR2(255):='http://site/rest/api/2/issue/key/attachments';
utl_req utl_http.req;
utl_resp utl_http.resp;
请求长度二进制整数;
答复2(32767);
p_请求_body clob;
l|u newline VARCHAR2(50):=chr(13)| chr(10);
lco_边界常数VARCHAR2(30):='AaB03x';
缓冲区原始(32767);
金额编号(15):=32767;
偏移量(15):=1;
l_附着斑点;
文件名VARCHAR2(255);
l_mime_类型VARCHAR2(255);
l_响应_头_名称varchar2(256);
l_响应_头_值varchar2(1024);
l_-response_-body varchar2(32767);
lang_上下文整数;
警告varchar2(1000);
blb blob;
tmp_blob blob默认为空_blob();
dest_偏移整数:=1;
src_偏移整数:=1;
开始
选择照片、文件名、MIMETYPE
放入l_附件,l_文件名,l_mime类型
来自Leanu照片
其中ID=156;
p|U请求|U主体:=l|U新线| |‘--’| lco|U边界| l|U新线||
'内容配置:表单数据;name=“file”;filename=“”||
l|U文件名| |'“'| | l| U新行| |'内容类型:'||
l|u mime|u type|l|u newline||
“内容传输编码:二进制”| | l|新行||
新线||
apex_web_服务.blob2clobbase64(l_附件)||
l|U新线--“lco|U边界--”;
dbms_lob.createtemporary(blb,FALSE);
目的地偏移量:=1;
src_偏移量:=1;
语言上下文:=0;
dbms_lob.converttoblob(blb,
p_请求_机构,
dbms_lob.getlength(p_请求_正文),
目的地偏移量,
src_偏移量,
0,
朗欧语境,
警告);
dbms_lob.append(blb,l_附件);
请求长度:=dbms\u lob.getlength(blb);
utl\U请求:=utl\U http.begin\U请求(url=>p\U url,
方法=>'POST',
http_version=>“http/1.1”);
utl_http.set_身份验证(utl_请求,'user','psw','Basic');
utl_http.set_头(utl_请求,'X-Atlassian-Token','no check');
utl_http.set_头(utl_-req,'User-Agent','Mozilla/4.0');
utl_http.set_头(utl_请求,
“内容类型”,
“多部分/表单数据;边界=“”| | lco| U边界| |“”);
dbms_输出。输入线(请求长度);
如果要求长度为32767,则
utl_http.set_头(utl_请求,“传输编码”,“分块”);
WHILE(偏移量<请求长度)循环
dbms_lob.read(blb、金额、偏移量、缓冲区);
utl_http.write_raw(utl_请求,缓冲区);
抵销:=抵销+金额;
端环;
如果结束;
utl_resp:=utl_http.get_响应(utl_请求);
dbms|u输出.put_行('响应>状态代码:'|| utl|u响应状态代码);
因为我在1。。utl_http.get_头计数(utl_resp)循环
utl_http.get_头(utl_resp,i,l_response_头名称,l_response_头值);
dbms|u output.put_line('Response>'|| l|u Response_header_name|124;':'| l|u Response_header_value);
端环;
utl_http.read_text(utl_resp,l_response_body,32767);
--utl_http.read_raw(utl_resp,response_body,32767);
dbms_output.put_行('Response body>');
dbms_output.put_line(l_response_body);
utl_http.end_响应(utl_resp);
例外情况
当UTL_HTTP.TOO_请求太多时
utl_http.END_响应(utl_resp);
结束;
此变体正在工作,但JIRA中的文件已损坏

编辑:使用编码进行思考。我尝试发送.txt文件,在JIRA中,文件内容是Base64格式