Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Friday, May 11, 2018 at 09:09amHello, I'm attempting to upload a PDF file using :
Upload a New Document through multipart/form-data
Based on this thread it appears it is possible to do this with UTL_HTTP as long as I post the binary output (and not base64, which I did try too and that also failed).
The code snippet below shows my initial HTTP Headers which points to a draft package in my sandbox.
l_upload_url := 'https://'||l_esignhost||'/api/packages/'||l_package_id||'/documents';
l_http_request := utl_http.begin_request(
url => l_upload_url,
method => 'POST',
http_version => 'HTTP/1.1'
);
utl_http.set_header(l_http_request, name => 'Authorization', VALUE => 'Basic '||l_api_key);
utl_http.set_header(l_http_request, 'Accept','text/html');
utl_http.set_header(l_http_request, 'Content-Type', 'multipart/form-data; boundary="' || lco_boundary || '"');
utl_http.set_header(l_http_request, 'Content-Length', l_request_body_length+l_request_body_length_blob+l_request_body_length_post);
-- I've also tried using Transfer-Encoding: chunked, but with the same results
Here is my request:
SQL> @esign_blob1.sql
Request post>
----THISxisMYxBoundary
Content-Disposition: form-data; name="payload"
{
"name": "Test_2.pdf" }
----THISxisMYxBoundary
Content-Disposition: form-data;
name="file"; filename="Test_2.pdf"
Content-Type:
application/pdf
Content-Transfer-Encoding: binary
-- This actually contains the calls to UTL_HTTP.WRITE_RAW
----THISxisMYxBoundary--
Response> Status Code: 500
Response> Reason Phrase: Internal Server Error
Response> HTTP Version: HTTP/1.1
Response> Server: nginx
Response> Date: Fri, 11 May 2018 17:03:51 GMT
Response> Content-Type: application/octet-stream
Response> Transfer-Encoding: chunked
Response> Connection: close
Response> X-Powered-By: Undertow
Response> Allow: GET, POST, HEAD, PUT, PATCH, DELETE
Response body>
500: Unhandled Server Error
PL/SQL procedure successfully completed.
Anything glaringly obvious as to what I'm doing wrong? Or have a method to determine why I'm getting a 500 ?
Thanks!
Andy K
PS Apologies if this is a re-post. I submitted something similar earlier, but haven't seen any signs of it.
Reply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Friday, May 11, 2018 at 09:16amReply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Friday, May 11, 2018 at 12:44pmReply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Monday, May 14, 2018 at 06:36amSQL> @esign1_base64.sql Request body> --THISxisMYxBoundary Content-Disposition: form-data; name="payload" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit { "name": "Test_2.pdf" } --THISxisMYxBoundary Content-Disposition: form-data; name="file"; filename="Test_2.pdf" Content-Type: application/pdf Content-Transfer-Encoding: base64 JVBERi0xLjUNCiW1tb
l0gL1ByZXYgODIyNjUvWFJlZlN0bSA4MTk4OD4+DQpzdGFydHhyZWYNCjgyODIx
DQolJUVPRg==
--THISxisMYxBoundary--
Response> Status Code: 500
Response> Reason Phrase: Internal Server Error
Response> HTTP Version: HTTP/1.1
Response> Server: nginx
Response> Date: Mon, 14 May 2018 14:56:26 GMT
Response> Content-Type: application/json
Response> Transfer-Encoding: chunked
Response> Connection: close
Response> X-Powered-By: Undertow
Response> Allow: GET, POST, HEAD, PUT, PATCH, DELETE
Response body>
{"technical":"DocumentConversionCommand failed and failed retrieving fallback.","messageKey":"error.internal.default","message":"Unexpected error. We apologize for any inconvenience this may have
caused you, please try again. If the problem persists, please contact our support team.","code":500,"name":"Unhandled Server Error"}
PL/SQL procedure successfully completed.
The above does seem to indicate that it was attempting to upload and then threw a conversion error? As another test, to take anything binary out of the picture I attempted to just upload a simple ascii text file, but still getting a 500. Do you have access to the server logs? Or is there a way I can set a flag to get more debug info?SQL> @esign_text1.sql Body Length: 353 URL: https://sandbox.esignlive.com/api/packages/2HmThBe9eZopqozAMY63n6TZ5jY=/documents ----THISxisMYxBoundary Content-Disposition: form-data; name="payload" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit { "name": "Test1.txt" } ----THISxisMYxBoundary Content-Disposition: form-data; name="file"; filename="Test1.txt" Content-Type: text/plain This is my sample file content! ----THISxisMYxBoundary-- Response> Status Code: 500 Response> Reason Phrase: Internal Server Error Response> HTTP Version: HTTP/1.1 Response> Server: nginx Response> Date: Mon, 14 May 2018 14:57:27 GMT Response> Content-Type: application/octet-stream Response> Transfer-Encoding: chunked Response> Connection: close Response> X-Powered-By: Undertow Response> Allow: GET, POST, HEAD, PUT, PATCH, DELETE Response body> Response length: 27 500: Unhandled Server Error PL/SQL procedure successfully completed.Thanks again!Reply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Monday, May 14, 2018 at 07:49amReply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Monday, May 14, 2018 at 08:16amSQL> @esign_blob1.sql Request post> Body Length: 334 Body Length: 82999 Body Length: 26 URL: https://sandbox.esignlive.com/api/packages/2HmThBe9eZopqozAMY63n6TZ5jY=/document s ----THISxisMYxBoundary Content-Disposition: form-data; name="payload" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit { "name": "Test_2.pdf" } ----THISxisMYxBoundary Content-Disposition: form-data; name="file"; filename="Test_2.pdf" Content-Type: application/pdf Content-Transfer-Encoding: binary
----THISxisMYxBoundary--
Response> Status Code: 500
Response> Reason Phrase: Internal Server Error
Response> HTTP Version: HTTP/1.1
Response> Server: nginx
Response> Date: Mon, 14 May 2018 17:14:21 GMT
Response> Content-Type: application/octet-stream
Response> Transfer-Encoding: chunked
Response> Connection: close
Response> X-Powered-By: Undertow
Response> Allow: GET, POST, HEAD, PUT, PATCH, DELETE
Response body>
500: Unhandled Server Error
PL/SQL procedure successfully completed.
Reply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Tuesday, May 15, 2018 at 05:23amReply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Tuesday, May 15, 2018 at 05:28amReply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Thursday, May 17, 2018 at 11:55amReply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Thursday, May 17, 2018 at 12:22pmPOST /api/packages/ HTTP/1.1 Host: sanbox.esignlive.com Connection: keep-alive Content-Length: 80357 Accept: application/json Authorization: Basic your_api_key Content-Type: multipart/form-data; boundary=----WebKitFormBoundarycywBKPMXcPHApu4C ------WebKitFormBoundarycywBKPMXcPHApu4C Content-Disposition: form-data; name="file"; filename="doc1.pdf" Content-Type: application/pdf %PDF-1.5 %µµµµ 1 0 obj >>> endobj.... ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="payload" {"name" : "document1"} ------WebKitFormBoundary7MA4YWxkTrZu0gW--Would you be able to use a tool like Fiddler to monitor the exact request going to esignlive?Reply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Friday, May 18, 2018 at 05:03am{"messageKey":"http.status.406","technical":"","messageLanguage":null,"packageId ":null,"entity":null,"message":"Not Acceptable","parameters":{},"code":406,"name":"Not Acceptable"}Which is sort of refreshing :) , just not sure how to fix it. I would think that it would use the package id from the URL . Thanks again!Reply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Friday, May 18, 2018 at 09:35am{"entity":null,"packageId":null,"messageKey":"http.status.406","technical":"","m essageLanguage":null,"parameters":{},"message":"Not Acceptable","code":406,"name":"Not Acceptable"}Reply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Friday, May 18, 2018 at 10:09amReply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Friday, May 18, 2018 at 10:16amReply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Friday, May 18, 2018 at 10:28amPOST /api/packages/2HmThBe9eZopqozAMY63n6TZ5jY=/documents HTTP/1.1 Host: sandbox.esignlive.com Authorization: Basic BlahBlahBlahBlah== Accept: text/html Content-Type: multipart/form-data; boundary="----THISxisMYxBoundary" Content-Length: 83248 Connection: keep-alive ----THISxisMYxBoundary Content-Disposition: form-data; name="file"; filename="Test_2.pdf" Content-Type: application/pdf %PDF-1.5 %���� 1 0 obj ... startxref 82821 %%EOF ----THISxisMYxBoundary Content-Disposition: form-data; name="payload" { "name": "Test_2" } ----THISxisMYxBoundary--Returns:Reply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Friday, May 18, 2018 at 10:38amReply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Monday, May 21, 2018 at 09:34amPOST /api/packages/2HmThBe9eZopqozAMY63n6TZ5jY=/documents HTTP/1.1 Host: sandbox.esignlive.com Authorization: Basic BlahBlahBlah== Content-Type: multipart/form-data; boundary="----THISxisMYxBoundary" Content-Length: 357 Connection: keep-alive ------THISxisMYxBoundary Content-Disposition: form-data; name="file"; filename="Test1.txt" Content-Type: text/plain This is my sample file content! ------THISxisMYxBoundary Content-Disposition: form-data; name="payload" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit { "name": "Test1.txt" }Finally! However, when I run the same fix for my PDF (the ultimate goal), the multipart error goes away and I get a JSON type message back. Still a 500, but at least something useful this time: Request:POST /api/packages/2HmThBe9eZopqozAMY63n6TZ5jY=/documents HTTP/1.1 Host: sandbox.esignlive.com Authorization: Basic BlahBlahBlah== Accept: text/html Content-Type: multipart/form-data; boundary="----THISxisMYxBoundary" Transfer-Encoding: chunked Connection: keep-alive ------THISxisMYxBoundary Content-Disposition: form-data; name="file"; filename="Test_2.pdf" Content-Type: application/pdf %PDF-1.5 %���� 1 0 obj ... startxref 82821 %%EOF ------THISxisMYxBoundary Content-Disposition: form-data; name="payload" { "name": "Test_2" } ------THISxisMYxBoundary--Response:{"messageKey":"error.internal.default","technical":"65533","message":"Unexpected error. We apologize for any inconvenience this may have caused you, please try again. If the problem persists, please contact our support team.","code":500,"name":"Unhandled Server Error"}Any idea what the 65533 is about? Maybe this time there might be something useful in the log. Thanks again for hanging in there with me!Reply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Monday, May 21, 2018 at 10:27amReply to: Trouble uploading a document through multipart/form-data via Oracle's UTL_HTTP
Tuesday, May 22, 2018 at 05:42am