
In addition to the static and dynamic HTML pages, a Web application generally contains additional static files such as pictures or logos. Files that belong to the application (such as background graphics, buttons, logos etc) must be differentiated from files that are part of application data (photos of houses for a real estate market place, book cover, employee pictures and so on). BSP applications that were developed using the SAP Web Application Server can be clearly separated.
The files that belong to the application are stored in the MIME Repository as a component of the BSP application, and are generally managed, transported and if necessary translated together with the BSPs, that is, the pages themselves. Pictures and binary objects that belong to the application data (master data and transaction data in the database) should be managed and transported with them.
Furthermore, there are scenarios in which documents can be imported into the system using the browser, that is, file upload.
See also:
You require knowledge of the following areas for file handling in BSP applications:
File upload/download using HTML pages
You can find an example of file upload in BSP application it00.
The BSP layout could look as follows:
<%@ page language="abap"%>
<html>
<body>
<h2> Form with File Upload and Download </h2>
<p>Choose a file for upload. The file will be echoed
to your browser if you select the checkbox below.
<form method="POST" enctype="multipart/form-data">
<table border=1 width="100%">
<tr>
<td> <input type=checkbox name="doEcho"> </td>
<td> <input type=checkbox name="doEcho" value="X">
(select for echo)</td>
</tr>
<tr>
<td> <input type=file name="echoFile"> </td>
<td> <input type=file name="echoFile"> </td>
</tr>
<tr>
<td> <input type=submit name="onInputProcessing(upload)"
value="Submit"> </td>
<td> <input type=submit name="onInputProcessing(upload)"
value="Submit"> </td>
</tr>
</table>
</form>
</body>
</html>
|
When you call the page, you see the following screen.

The actual upload takes place, when you choose Submit, in the OnInputProcessing event handler:
* event handler for checking and processing user input and
* for defining navigation
* file upload and echo
data: entity type ref to if_http_entity,
file type xstring,
content_type type string,
content_length type string,
num_multiparts type i,
i type i value 1,
doEcho type string,
value type string.
* find multipart containing file
num_multiparts = request->num_multiparts( ).
while i <= num_multiparts.
entity = request->get_multipart( i ).
value = entity->get_header_field( '~content_filename' ).
if not value is initial.
* found a file!
navigation->set_parameter( name = 'content_filename'
value = value ).
content_type = entity->get_header_field( 'Content-Type' ).
navigation->set_parameter( name = 'content_type'
value = content_type ).
* get file content
file = entity->get_data( ).
* get file size
content_length = xstrlen( file ).
navigation->set_parameter( name = 'content_length'
value = content_length ).
* echo/download the same file again?
doEcho = request->get_form_field( 'doEcho' ).
if doEcho is not initial.
* set response data to be the file content
runtime->server->response->set_data( file ).
* set the mime-type and file size in the response
runtime->server->response->set_header_field(
name = 'Content-Type'
value = content_type ).
runtime->server->response->set_header_field(
name = 'Content-Length'
value = content_length ).
runtime->server->response->delete_header_field(
name = 'Cache-Control' ).
runtime->server->response->delete_header_field(
name = 'Expires' ).
endif.
exit.
endif.
i = i + 1.
endwhile.
if doEcho is not initial.
* signal to the BSP runtime that the response data is
* complete and no onLayout method should be called to
* create the response
navigation->response_complete( ).
else.
navigation->goto_page( 'transition_parameter_upload.htm' ).
endif.
|
If you have specified a file and activated the echo checkbox, you see the content of the file that is selected in the browser:
