Hello,
I am trying to hit a rest endpoint in plsql which returns a pdf as a file download, and return it to the browser through an apex application.
I am able to hit the endpoint from Postman and have it return well formatted pdf.
When I do it with plsql, I get the right amount of pages, but the pages are all blank. Upon further inspection, the pdf headers and footers are well-formatted, but the pdf binary in between seems to be completely different.
Here is the code that is hitting the endpoint and returning the results.
BEGIN
l_req := utl_http.begin_request(url => l_report_url);
utl_http.set_header(r => l_req,
NAME => 'Cookie',
VALUE => g_session_key);
l_resp := utl_http.get_response(r => l_req);
IF (l_resp.status_code <> utl_http.http_ok) THEN
RETURN - 1;
END IF;
BEGIN
dbms_lob.createtemporary(l_blob_total, FALSE);
LOOP
utl_http.read_line(r => l_resp, data => l_clob);
dbms_lob.append(dest_lob => l_blob_total, src_lob => utl_raw.cast_to_raw(l_clob));
l_clob := NULL;
END LOOP;
EXCEPTION
WHEN utl_http.end_of_body THEN
NULL;
END;
utl_http.end_response(l_resp);
htp.init;
owa_util.mime_header('application/pdf', FALSE);
htp.p('Content-length: ' || dbms_lob.getlength(l_blob_total));
htp.p('Content-Disposition: attachment; filename="report.pdf"');
owa_util.http_header_close;
wpg_docload.download_file(p_blob => l_blob_total);
RETURN 0;
END get_report_pdf;
The result is that I download a pdf, it has the right number of pages, but the pages are all blank.
Any help would be very appreciated.