Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

UTL_HTTP error uploading images

User_7W8VWSep 18 2019 — edited Sep 18 2019

Hello,

While trying to send an image using REST API, I am getting errors when trying to upload images that are bigger than a set amount of size.

I have tested in 12c and 11g with similar results.

This is the snippet of the code I use:

begin  

    v_clob_length := dbms_lob.getlength(tmp_blob);

    req := utl_http.begin_request(requesturl, 'PUT', ' HTTP/1.1');  

    utl_http.set_header(req, 'content-length', v_clob_length);

    utl_http.set_header(req, 'content-type', 'text/plain');

    buffersize := 1024;

    if ( v_clob_length > 0 ) then

        utl_http.set_header(req, 'Transfer-Encoding', 'chunked');

        utl_http.set_body_charset('UTF-8');

        while ( offset < v_clob_length ) loop

            if offset + buffersize >= v_clob_length then

                amount := v_clob_length - offset + 1;

            else

                amount := buffersize;

            end if;

            dbms_lob.read(tmp_blob, amount, offset, buffer);

            dbms_output.put_line(amount || ' - ' || offset || '/' || v_clob_length || ' - ' || length(buffer));

            utl_http.write_raw(req, buffer);

            offset := offset + amount;

        end loop;

    else

        utl_http.write_text(req, null);

    end if;

    res := utl_http.get_response(req);

    begin

        loop

            utl_http.read_line(res, buffer);

            dbms_output.put_line(buffer);

            if ( length(buffer) > 0 ) then

                v_clob := v_clob || to_clob(to_char(buffer));

            end if;

        end loop;

        utl_http.end_response(res);

    exception

        when utl_http.end_of_body then

            utl_http.end_response(res);

    end;

end;

/

This works as long as the image is bellow the threshold:

amount - offset/lob len - buffer

1024 - 1/2784 - 2048

1024 - 1025/2784 - 2048

736  - 2049/2784 - 1472

PL/SQL procedure successfully completed.

If I try to upload bigger images, 12c returns either an ORA-600 with an unknown error code (will open SR about it), or ORA-29273: HTTP request failed

version: 12.2.0.1.0

  

Error report -

ORA-29273: HTTP request failed

ORA-12547: TNS:lost contact

ORA-06512: at "SYS.UTL_HTTP", line 606

ORA-06512: at "SYS.UTL_HTTP", line 1212

ORA-06512: at line 133

29273. 00000 -  "HTTP request failed"

*Cause:    The UTL_HTTP package failed to execute the HTTP request.

*Action:   Use get_detailed_sqlerrm to check the detailed error message.

           Fix the error and retry the HTTP request.

          

Error report -

ORA-00600: internal error code, arguments: [nhpGetHTTPIOClientError_1], [], [], [], [], [], [], [], [], [], [], []

ORA-06512: at "SYS.UTL_HTTP", line 606

ORA-06512: at "SYS.UTL_HTTP", line 1212

ORA-06512: at line 133

00600. 00000 -  "internal error code, arguments: [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s]"

*Cause:    This is the generic internal error number for Oracle program

           exceptions. It indicates that a process has encountered a low-level,

           unexpected condition. The first argument is the internal message

           number. This argument and the database version number are critical in

           identifying the root cause and the potential impact to your system.

The error occurs after 16k being written, if I change the buffersize to 1, the error point is clearer:

amount - offset/lob len - buffer

1024 - 1/165227 - 2048

1024 - 1025/165227 - 2048

1024 - 2049/165227 - 2048

1024 - 3073/165227 - 2048

1024 - 4097/165227 - 2048

1024 - 5121/165227 - 2048

1024 - 6145/165227 - 2048

-- error

buffersize := 1;

...

amount - offset/lob len - buffer

1 - 8189/165227 - 2

1 - 8190/165227 - 2

1 - 8191/165227 - 2

1 - 8192/165227 - 2

1 - 8193/165227 - 2

-- error

On 11g, the error is a little bit different, TNS: packet writer failure, and it occurs later after 24k have been written:

version: 11.2.0.1.0

...

amount - offset/lob len - buffer

1 - 12286/36531 - 2

1 - 12287/36531 - 2

1 - 12288/36531 - 2

1 - 12289/36531 - 2

ERROR at line 1:

ORA-29273: HTTP request failed

ORA-06512: at "SYS.UTL_HTTP", line 1324

ORA-12571: TNS:packet writer failure

ORA-06512: at line 49

The test is being done with a localhost address and windows firewall is disabled. I tried POST method as well and the behavior is the same.

Any help appreciated.

Thanks!

Comments
Post Details
Added on Sep 18 2019
1 comment
771 views