[ABAP] MIME-Repository: Verzeichnis lesen

DATA: it_file_list TYPE string_table.

* MIME-API holen
DATA(o_mime_rep) = cl_mime_repository_api=>get_api( ).

TRY.
* Bild aus dem MIME-Repository laden
    o_mime_rep->file_list( EXPORTING
                             i_url             = '/SAP/BC/BSP'
                             i_recursive_call  = abap_true
*                             i_check_authority = abap_false
                           IMPORTING
                             e_files           = it_file_list ).

    cl_demo_output=>display( it_file_list ).
  CATCH cx_root INTO DATA(e).
    WRITE : / e->get_text( ).
ENDTRY.

[ABAP] MIME-Repository: logische Objekt-ID, physiche Object-ID, Berechtigungen

DATA: lv_loio	TYPE skwf_io.
DATA: lv_is_folder TYPE boole_d.

DATA(o_mime_rep) = cl_mime_repository_api=>get_api( ).

TRY.
* logische IO zu MIME-Objekt holen
    o_mime_rep->get_io_for_url( EXPORTING
                                  i_url       = '/SAP/PUBLIC/xyz.jpg'
                                IMPORTING
                                  e_is_folder = lv_is_folder
                                  e_loio      = lv_loio ).

    WRITE: / lv_is_folder.
    WRITE: / lv_loio.

    DATA: lv_error TYPE skwf_error.
    DATA: it_phios TYPE STANDARD TABLE OF skwf_io WITH DEFAULT KEY.

* physical IOs zu log. IO holen
    CALL FUNCTION 'SKWF_LOIO_ALL_PHIOS_GET'
      EXPORTING
        loio  = lv_loio
      IMPORTING
        error = lv_error
      TABLES
        phios = it_phios.

    LOOP AT it_phios ASSIGNING FIELD-SYMBOL(<p>).

      DATA: lv_err TYPE skwf_error.

* Berechtigungen zu physical IO prüfen
      CALL FUNCTION 'SKWF_AUTH_OBJECT_CHECK'
        EXPORTING
          activity = skwfa_c_act_read
          object   = <p>
        IMPORTING
          error    = lv_err.

      IF lv_err-type = 'E'.
      ELSE.
        WRITE: / <p>.
      ENDIF.

    ENDLOOP.

  CATCH cx_root INTO DATA(e).
    WRITE: / e->get_text( ).
ENDTRY.

[ABAP] Bild (JPEG) aus dem MIME-Repository laden und anzeigen

* Demo-Programm: SAP_PICTURE_DEMO
DATA: o_dock TYPE REF TO cl_gui_docking_container.

PARAMETERS: p_name TYPE string. " Dummy-Parameter

AT SELECTION-SCREEN OUTPUT.

  IF NOT o_dock IS BOUND.
* Dockingcontainer erzeugen
    o_dock = NEW #( repid = sy-repid
                    dynnr = sy-dynnr
                    side  = cl_gui_docking_container=>dock_at_right
                    ratio = 50 ).

    DATA: lv_xstr TYPE xstring.

* MIME-API holen
    DATA(o_mime_rep) = cl_mime_repository_api=>get_api( ).

* Bild aus dem MIME-Repository laden
    o_mime_rep->get( EXPORTING
                       i_url = '/SAP/PUBLIC/Test123.jpg'
                       i_check_authority = abap_false
                     IMPORTING
                       e_content = lv_xstr ).

* xstring nach binary (RAW) wandeln
    DATA(it_bin_data) = cl_bcs_convert=>xstring_to_solix( lv_xstr ).

    DATA: lv_url TYPE swk_url.

* temporäre URL auf das Bild erzeugen
    CALL FUNCTION 'DP_CREATE_URL'
      EXPORTING
        type                 = 'image/jpeg' " https://wiki.selfhtml.org/wiki/MIME-Type/%C3%9Cbersicht
        subtype              = 'jpg'
      TABLES
        data                 = it_bin_data
      CHANGING
        url                  = lv_url
      EXCEPTIONS
        dp_invalid_parameter = 1
        dp_error_put_table   = 2
        dp_error_general     = 3
        OTHERS               = 4.

* Bild über die URL laden und anzeigen
    DATA(o_pic) = NEW cl_gui_picture( parent = o_dock ).
    o_pic->set_display_mode( display_mode = cl_gui_picture=>display_mode_fit_center ).
    o_pic->load_picture_from_url_async( lv_url ).
  ENDIF.

Weiterführende Infos: Link

[ABAP] Bild (JPEG) vom lokalen Rechner ins MIME-Repository hochladen

* Dateiname der Bilddatei zum hochladen
PARAMETERS: p_fname TYPE file_table-filename OBLIGATORY.
* Speicherpfad im MIME-Repository, muss vorhanden sein, andernfalls mit o_mime_rep->create_folder( ) erzeugen
PARAMETERS: p_mpath TYPE string DEFAULT '/SAP/PUBLIC/Test123.jpg' OBLIGATORY.

* wenn die F4-Hilfe für den Dateinamen aufgerufen wird
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

  DATA: lv_rc TYPE i.
  DATA: it_files TYPE filetable.
  DATA: lv_action TYPE i.

* File-Tabelle leeren, da hier noch alte Einträge von vorherigen Aufrufen drin stehen können
  CLEAR it_files.

* FileOpen-Dialog aufrufen
  TRY.
      cl_gui_frontend_services=>file_open_dialog( EXPORTING
                                                    file_filter = |jpg (*.jpg)\|*.jpg\|{ cl_gui_frontend_services=>filetype_all }|
                                                  CHANGING
                                                    file_table  = it_files
                                                    rc          = lv_rc
                                                    user_action = lv_action ).

      IF lv_action = cl_gui_frontend_services=>action_ok.
* wenn Datei ausgewählt wurde
        IF lines( it_files ) > 0.
* ersten Tabelleneintrag lesen
          p_fname = it_files[ 1 ]-filename.
        ENDIF.
      ENDIF.

    CATCH cx_root INTO DATA(e_text).
      MESSAGE e_text->get_text( ) TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.

START-OF-SELECTION.
  DATA: lv_filesize TYPE i.
  DATA: it_bin_data TYPE STANDARD TABLE OF raw255.

* Bild auf Appl. Server hochladen (binary)
  cl_gui_frontend_services=>gui_upload( EXPORTING
                                          filename = |{ p_fname }|
                                          filetype = 'BIN'
                                        IMPORTING
                                          filelength = lv_filesize
                                        CHANGING
                                          data_tab = it_bin_data ).

  DATA: lv_xstr TYPE xstring.

* RAW (binary) nach xstring
  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
    EXPORTING
      input_length = lv_filesize
    IMPORTING
      buffer       = lv_xstr
    TABLES
      binary_tab   = it_bin_data
    EXCEPTIONS
      failed       = 1
      OTHERS       = 2.

* MIME-API holen
  DATA(o_mime_rep) = cl_mime_repository_api=>get_api( ).

* Bild im MIME-Repository speichern
* Objektkatalogeintrag wird erstellt, evtl. bestehende Dateien werden überschrieben
  o_mime_rep->put( i_url = p_mpath
                   i_content = lv_xstr
                   i_check_authority = abap_false ).