Skip to Content
0
Jul 31, 2018 at 11:30 AM

Upload Client File thru BSP application

51 Views

Hi All,

I had developed the BSP application, upload the particular pdf file into the particular location of the external server. it is working fine when the user input the file and press the upload button, but the business requirement is, the user no need to select the file, it should uplaod the particular file from the specific directory. Please advice in below is the code.

CASE event_id.

WHEN 'upload'.

* find number of multiparts of file

      ld_entity = request->add_multipart( ).

      ld_numparts  = request->num_multiparts( ).

      ld_entity->set_header_field( name = '~content_filename' value = 'C:\sdcard1\inv001.pdf').

      ld_entity->set_header_field( name = 'Content-Type' value = 'application/pdf').

    do ld_numparts  times.

      ld_entity = request->get_multipart( sy-index ).
      ld_value  = ld_entity->get_header_field( '~content_filename' ).

*      ld_entity->send( ).
      if not ld_value is initial.
       ld_filename = ld_value.
        ld_type = ld_entity->get_header_field( 'Content-Type' ).

*       Get file content

        test = ld_data = ld_entity->get_data( ).



*       Get size of file

        ld_length = xstrlen( ld_data ).



*       Move BINARY data into itab 1022 characters at a time

        ld_datatmp = ld_data.

        ld_lengthtmp = ld_length.

        while ld_lengthtmp > 1022.

          wa_binary_content-line = ld_datatmp(1022).



          append wa_binary_content to it_binary_content.

          shift ld_datatmp by 1022 places in byte mode.

          ld_lengthtmp = xstrlen( ld_datatmp ).

        endwhile.



*       Move remainder of file into table

        wa_binary_content-line = ld_datatmp.

        append wa_binary_content to it_binary_content.

        else.

          CHECK 1 = 0.

      endif.



    enddo.