Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
RenaldWittwer
Contributor
0 Kudos

h2.

Introduction




A few weeks ago a customer came and asked for a website with an input field,
type file, with a preselected file. I said to him that this is impossible, because
of the security rules in the web. He answered that I have to solve the problem,
because he promised it to the department.

I searched the web, but I did not find any solution. After some investigation
it was clear that I will not solve the problem with pure-html. I found a Java-Applet
that seems to solve my problem. I tested it on the WAS, it works!


You find the Applet that I use in this weblog here: jupload.biz (http://jupload.biz).
Please be fair, if You use the Applet productive, pay like described on the
homepage.

Scenario

To make the problem a little bit clearer, I will describe the scenario. If

You are only interested at the solution, You can skip this.

We have a non-SAP-Application, that writes a file on the local machine, a xml-file.

After that the user has the opportunity to call a link, which starts a browser

with the URL of a WAS-BSP-Application. We want to make it as easy as possible,

so we give the path and the name of the written file in the URL. So the User

has only to submit the page.

Implementation

To show how the Applet works I created three bsp-pages:

    • default.htm - On this page we start the application, on this page you can

find the applet

    • load.htm - From default.htm we jump on load.htm. We use the Eventhandler

OnInitialization, where we read the file-data (multipart). After that we save

the data in a server side cookie

    • show.htm - Read the server side cookie, written in load.htm. Display the

data

First of all build a bsp-application, in this example I named it Z_JUPLOAD.

  Import the jar-file of the Applet (jupload.jar) that You uploaded from jupload.biz  (http://jupload.biz)

  as a mime into the new application. Because this weblog is not about authentification

  set a default user in transaction SICF for this application.</p>

default.htm

<p>The layout of default.htm. This page needs a page attribute, name: fileinput,
  auto: yes, type: string. With this URL-parameter you can preselect the file.</p>
<p>Sorry but for formatting purposes the following code segments will be contained
  only within Textareas:</p>
<p>
  <textarea rows="10" cols="79">
<%@page language="abap" %>
<html>
  <body>
      <table width='550' class="clsTable">
        <tr>
          <td> </td>
          <td>
          <applet
             code   ="JUpload/startup.class"
             archive="./jupload.jar"
             width  ="500"
             height ="300"
             mayscript
             name   ="JUpload"
             alt    ="JUpload by www.jupload.biz">
               <!-- Java Plug-In Options -->
               <param name="progressbar" value="true">
               <param name="boxmessage" value="Loading JUpload Applet ...">
               <%-- language dependend Buttons --%>
               <param name="labelAdd" value="Add">
               <param name="labelRemove" value="Remove">
               <param name="labelUpload" value="Upload">
               <param name="labelStopUpload" value="Stop Upload">

               <%-- Links --%>
               <param name="actionURL" value="load.htm">
               <param name="completeURL" value="show.htm">

               <%-- In this example only one file --%>
               <param name="maxNumberFiles" value="1">

               <%if not fileinput is initial.%>
               <param name="preselectedFiles" value="<%= fileinput%>">
               <%endif.%>

               <param name="checkResponse" value="true">
               <param name="realTimeResponse" value="true">
               <!-- IF YOU HAVE PROBLEMS, CHANGE THIS TO TRUE BEFORE CONTACTING SUPPORT -->
               <param name="debug" value="false">

               Your browser does not support applets. Or you have disabled applet in your options.

               To use this applet, please install the newest version of Sun's java. You can get it from java.com  (http://www.java.com/)

           </applet>

       </td>

     </tr>

   </table>

  </body>

</html>

</textarea>

</p>

load.htm

On this page we need the Eventhandler OnInitialization

  • event handler for data retrieval

data: i_num     type i.

data: i_entity  type ref to if_http_entity.

data: i_string type string,

      i_uname  type string.

data: itab_header_fields type tihttpnvp.

data: i_date type d,

      i_time type t.

  • Get the number of multiparts

call method runtime->server->request->num_multiparts

  receiving

    num = i_num.

  • Search in all multiparts for the first file

do i_num times.

  call method runtime->server->request->get_multipart

    exporting

      index  = sy-index

    receiving

      entity = i_entity.

  call method i_entity->get_header_fields

    changing

      fields = itab_header_fields.

  read table itab_header_fields with key name = '~content_name'

                                         value = 'uploadedFiles0'

                         transporting no fields.

  if sy-subrc = 0.

  •   This works only, if the file is a textfile

    call method i_entity->get_cdata

      receiving

        data = i_string.

    exit.

  endif.

enddo.

  • Save the data in a serverside cookie

i_uname = sy-uname.

i_date = sy-datum + 1.

i_time = sy-uzeit.

call method cl_bsp_server_side_cookie=>set_server_cookie

  exporting

    name                  = 'files'

    application_name      = runtime->application_name

    application_namespace = runtime->application_namespace

    username              = i_uname

    session_id            = runtime->session_id

    data_value            = i_string

    data_name             = 'file1'

    expiry_time_abs       = i_time

    expiry_date_abs       = i_date

  •   EXPIRY_TIME_REL       =

  •   EXPIRY_DATE_REL       =

    .

</textarea>

</p>

show.htm

On this page we read the data from the server side cookie in the Eventhandler

OnInitialization. This page needs one page attribute, name: file1, auto: no,

type: string. We will read the server side cookie into this variable and display

it in the layout.

  • event handler for data retrieval

data: i_uname type string.

i_uname = sy-uname.

call method cl_bsp_server_side_cookie=>get_server_cookie

  exporting

    name                  = 'files'

    application_name      = runtime->application_name

    application_namespace = runtime->application_namespace

    username              = i_uname

    session_id            = runtime->session_id

    data_name             = 'file1'

  • IMPORTING

  •    EXPIRY_DATE           =

  •    EXPIRY_TIME           =

  changing

    data_value            = file1

    .

</textarea>
</p>
<p>In the Layout we show the file-data. This makes only sense if you downloaded
  a textfile.</p>
<p>
  <textarea rows="10" cols="79">
<%@page language="abap"%>
<html>

  <head>
  </head>

  <body class="bspBody1">
    File:<br>
    <%=file1%>
  </body>

</html> 
</textarea>
</p>

Result

If we both have not done any error, You should get this result:

!https://weblogs.sdn.sap.com/weblogs/images/12076/show.jpg|height=164|alt=image|width=515|src=https:/...!</body>

5 Comments