Entering content frame

Function documentation File Upload in BSP Applications Locate the document in its SAP Library structure


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:

Uploading Files and Manipulating their Content


You require knowledge of the following areas for file handling in BSP applications:


You can find an example of file upload in BSP application it00.

The BSP layout could look as follows:

<%@page language="abap"%>




<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%">


      <td> &lt;input type=checkbox name="doEcho"&gt; </td>

      <td> <input type=checkbox name="doEcho" value="X"> (select for echo)</td>



      <td> &lt;input type=file name="echoFile"&gt; </td>

      <td> <input type=file name="echoFile"> </td>



      <td> &lt;input type=submit name="onInputProcessing(upload)" value="Submit"&gt; </td>

      <td> <input type=submit name="onInputProcessing(upload)" value="Submit"> </td>







When you call the page, you see the following screen.

This graphic is explained in the accompanying text

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


            name  = 'Content-Type'

            value = content_type ).


            name  = 'Content-Length'

            value = content_length ).


            name = 'Cache-Control' ).


            name = 'Expires' ).






      i = i + 1.



    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( ).


      navigation->goto_page( 'transition_parameter_upload.htm' ).


If you have specified a file and activated the echo checkbox, you see the content of the file that is selected in the browser:

This graphic is explained in the accompanying text




Leaving content frame