The addition of several new procedures in the cloud_http
PSQL package enable the processing of binary and text files through a web form. The file(s) can then further be processed for instance parsing it as an XML, JSON, CSV or Excel file.
New cloud_http
procedures
The following procedures have been added to the cloud_http
package:
get_request_form_file_name
: Gets the first form file name of the key specified as text value parameter.get_request_form_file_content_type
: Gets the first form file content type of the key specified as text value parameter.get_request_form_file_content_disposition
: Gets the first form file content disposition of the key specified as text value parameter.get_request_form_file_length
: Gets the first form file length of the key specified as text value parameter.get_request_form_file_contents
: Gets the first form file contents in binary format of the key specified as text value parameter. Useto_char
when UTF-8 to use asvarchar2
text.
Sample PSQL-code to process a file
The following sample code allows you to upload a JPEG image file and then display it in a web page.
Place the PSQL-code in a module as shown in the picture and execute it on any database:
PSQL-code:
declare
p_run boolean;
--
l_binary blob;
l_filename varchar2;
l_payload blob;
l_payload_base64_encoded varchar2;
begin
--
-- Get parameters.
--
p_run := cast(cloud_http.get_request_form_value('p_run') as boolean);
--
if coalesce(p_run, false) = false
then
--
-- Display a form tp upload a file.
--
cloud_http.set_use_template(true);
cloud_http.set_template_step_name(translate_resources('{res:itgen_parameters}'));
cloud_http.append_line_to_response_body_text('<form method="post" enctype="multipart/form-data">');
cloud_http.append_line_to_response_body_text('<input type="hidden" id="p_run" name="p_run" value="true"/>');
cloud_http.append_line_to_response_body_text('<ul>');
cloud_http.append_line_to_response_body_text('<li><label for="p_file">' || translate_resources('{res:itgen_file}') || '</label></li><li><input type="file" id="p_file" name="p_file" accept=".jpg" required/></li>');
cloud_http.append_line_to_response_body_text('<li><input type="submit" value="Start"/></li>');
cloud_http.append_line_to_response_body_text('</ul>');
cloud_http.append_line_to_response_body_text('</form>');
else
--
-- Process form.
--
l_filename := cloud_http.get_request_form_file_name('p_file');
--
if l_filename is null
then
raise_application_error('sample001', 'The file name is empty.');
end if;
--
l_payload := cloud_http.get_request_form_file_contents('p_file');
--
if l_payload is null
then
raise_application_error('sample002', 'The file payload is empty.');
end if;
--
l_payload_base64_encoded := base64_encode(l_payload);
--
cloud_http.set_use_template(true);
--
-- Display file as na image.
--
cloud_http.append_line_to_response_body_text
( '<img src="data:image/jpg;base64, '
|| l_payload_base64_encoded
|| '" />'
);
end if;
end;
Execution Sample
xxxDuring execution, first the user is offered the opportunity to specify a file:
Upon selection of the Start-button, the file is uploaded and rendered in a web page: