[ABAP] Konstanten für gängige MIME-Typen (IF_REST_MEDIA_TYPE, CL_FXS_MIME_TYPES)

Variante 1 (IF_REST_MEDIA_TYPE)

Konstante                       MIME-Typ
--------------------------------------------------------------
gc_all                          '*/*'
gc_appl_all                     'application/*'
gc_appl_xml                     'application/xml'
gc_appl_xhtml_xml               'application/xhtml+xml'
gc_appl_atom_xml                'application/atom+xml'
gc_appl_atom_xml_feed           'application/atom+xml;type=feed'
gc_appl_atom_xml_entry          'application/atom+xml;type=entry'
gc_appl_atomcat_xml             'application/atomcat+xml'
gc_appl_atomsvc_xml             'application/atomsvc+xml'
gc_appl_opensearch_descr_xml    'application/opensearchdescription+xml'
gc_appl_all_xml                 'application/*+xml'
gc_appl_java                    'application/java'
gc_appl_java_archive            'application/java-archive'
gc_appl_json                    'application/json'
gc_appl_json_odata_verbose      'application/json;odata=verbose'
gc_appl_mac_binhex40            'application/mac-binhex40'
gc_appl_mathml_xml              'application/mathml+xml'
gc_appl_msword                  'application/msword'
gc_appl_octet_stream            'application/octet-stream'
gc_appl_onenote                 'application/onenote'
gc_appl_pdf                     'application/pdf'
gc_appl_postscript              'application/postscript'
gc_appl_rdf_xml                 'application/rdf+xml'
gc_appl_relax_ng_compact_synt   'application/relax-ng-compact-syntax'
gc_appl_rss_xml                 'application/rss+xml'
gc_appl_rtf                     'application/rtf'
gc_appl_sparql_results_json     'application/sparql-results+json'
gc_appl_sparql_results_xml      'application/sparql-results+xml'
gc_appl_trix                    'application/trix'
gc_appl_vnd_google_earthkmlxml  'application/vndgoogle-earthkml+xml'
gc_appl_vnd_google_earth_kmz    'application/vndgoogle-earthkmz'
gc_appl_vnd_mozilla_xul_xml     'application/vndmozillaxul+xml'
gc_appl_vnd_ms_cab_compressed   'application/vndms-cab-compressed'
gc_appl_vnd_ms_excel            'application/vndms-excel'
gc_appl_vnd_ms_powerpoint       'application/vndms-powerpoint'
gc_appl_vnd_ms_project          'application/vndms-project'
gc_appl_vnd_sun_wadl_xml        'application/vndsunwadl+xml'
gc_appl_voicexml_xml            'application/voicexml+xml'
gc_appl_zip                     'application/zip'
gc_audio_all                    'audio/*'
gc_audio_basic                  'audio/basic'
gc_audio_midi                   'audio/midi'
gc_audio_mpeg                   'audio/mpeg'
gc_image_all                    'image/*'
gc_image_bmp                    'image/bmp'
gc_image_gif                    'image/gif'
gc_image_jpeg                   'image/jpeg'
gc_image_png                    'image/png'
gc_image_svg_xml                'image/svg+xml'
gc_image_tiff                   'image/tiff'
gc_message_all                  'message/*'
gc_model_all                    'model/*'
gc_model_vrml                   'model/vrml'
gc_multipart_all                'multipart/*'
gc_multipart_form_data          'multipart/form-data'
gc_text_all                     'text/*'
gc_text_calendar                'text/calendar'
gc_text_css                     'text/css'
gc_text_csv                     'text/csv'
gc_text_html                    'text/html'
gc_text_javascript              'text/javascript'
gc_text_n_triples               'text/n-triples'
gc_text_n3                      'text/n3'
gc_text_plain                   'text/plain'
gc_text_tab_separated_values    'text/tab-separated-values'
gc_text_uri_list                'text/uri-list'
gc_video_all                    'video/*'
gc_video_mp4                    'video/mp4'
gc_video_mpeg                   'video/mpeg'
gc_video_quicktime              'video/quicktime'
gc_appl_www_form_url_encoded    'application/x-www-form-urlencoded'
gc_multipart_mixed              'multipart/mixed'
gc_appl_http                    'application/http'

Variante 2 (CL_FXS_MIME_TYPES)

Konstante                           MIME-Typ
--------------------------------------------------------------
CL_FXS_MIME_TYPES=>CO_BINARY        'application/octet-stream'
CL_FXS_MIME_TYPES=>CO_PDF           'application/pdf'
CL_FXS_MIME_TYPES=>CO_IMAGE_BITMAP  'image/x-ms-bmp'
CL_FXS_MIME_TYPES=>CO_IMAGE_PNG     'image/png'
CL_FXS_MIME_TYPES=>CO_IMAGE_GIF     'image/gif'
CL_FXS_MIME_TYPES=>CO_IMAGE_TIFF    'image/tiff'
CL_FXS_MIME_TYPES=>CO_IMAGE_JPEG    'image/jpeg'

[ABAP] Mit Hilfe der Klasse cl_fxs_image_processor Infos zu einem Bild auslesen, Größe verändern (Resize) und Bildformat konvertieren (Convert)

* Im Beispiel wird das Eingabebild (PNG) nach JPG konvertiert und auf 800x600px in der Größe verändert

* Dateiname der Bilddatei zum hochladen
PARAMETERS: p_fname TYPE file_table-filename OBLIGATORY.
PARAMETERS: p_width TYPE i DEFAULT 800.
PARAMETERS: p_height TYPE i DEFAULT 600.

* 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 = |png (*.png)\|*.png\|{ 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.

  TRY.
      DATA: lv_filesize TYPE w3param-cont_len.
      DATA: lv_filetype TYPE w3param-cont_type.
      DATA: it_bin_data TYPE w3mimetabtype.

      WRITE: / p_fname.

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

* solix -> xstring
      DATA(lv_img_data) = cl_bcs_convert=>solix_to_xstring( it_solix = it_bin_data ).

* FXS-Objekt holen
      DATA(o_ip) = NEW cl_fxs_image_processor( ).

* Bild zum Konverter hinzufügen
      DATA(lv_hndl) = o_ip->add_image( iv_data = lv_img_data ).

      DATA: lv_mimetype	TYPE string.
      DATA: lv_xres	TYPE i.
      DATA: lv_yres	TYPE i.
      DATA: lv_xdpi	TYPE i.
      DATA: lv_ydpi	TYPE i.
      DATA: lv_bitdepth	TYPE i.

* Infos holen
      o_ip->get_info( EXPORTING
                        iv_handle   = lv_hndl
                      IMPORTING
                        ev_mimetype = lv_mimetype
                        ev_xres     = lv_xres
                        ev_yres     = lv_yres
                        ev_xdpi     = lv_xdpi
                        ev_ydpi     = lv_ydpi
                        ev_bitdepth = lv_bitdepth ).

* Infos ausgeben
      WRITE: / 'MIME-Type:', lv_mimetype.
      WRITE: / '        X:', lv_xres.
      WRITE: / '        Y:', lv_yres.
      WRITE: / '    X-DPI:', lv_xdpi.
      WRITE: / '    Y-DPI:', lv_ydpi.
      WRITE: / '      Bit:', lv_bitdepth.

* Größe ändern (Resize)
      o_ip->resize( EXPORTING
                      iv_handle = lv_hndl
                      iv_xres   = p_width
                      iv_yres   = p_height ).

* Konvertierung (Convert) nach JPG
* Zielformate können nur sein (andernfalls gibt es eine Exception vom Typ cx_sy_range_out_of_bounds):
*   cl_fxs_mime_types=>co_image_bitmap
*   cl_fxs_mime_types=>co_image_png
*   cl_fxs_mime_types=>co_image_jpeg
      o_ip->convert( EXPORTING
                      iv_handle = lv_hndl
                      iv_format = cl_fxs_mime_types=>co_image_jpeg ).

* Infos holen
      o_ip->get_info( EXPORTING
                        iv_handle   = lv_hndl
                      IMPORTING
                        ev_mimetype = lv_mimetype
                        ev_xres     = lv_xres
                        ev_yres     = lv_yres
                        ev_xdpi     = lv_xdpi
                        ev_ydpi     = lv_ydpi
                        ev_bitdepth = lv_bitdepth ).

* Infos ausgeben
      WRITE: / 'MIME-Type:', lv_mimetype.
      WRITE: / '        X:', lv_xres.
      WRITE: / '        Y:', lv_yres.
      WRITE: / '    X-DPI:', lv_xdpi.
      WRITE: / '    Y-DPI:', lv_ydpi.
      WRITE: / '      Bit:', lv_bitdepth.

* Binärdaten (xstring) des Bildes holen
      DATA(lv_img_conv_data) = o_ip->get_image( EXPORTING iv_handle = lv_hndl ).

* xstring -> solix
      DATA(it_img_conv_data) = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_img_conv_data ).

      WRITE: / |{ p_fname }.jpg|.

* Image lokal speichern
      cl_gui_frontend_services=>gui_download( EXPORTING
                                                filename     = |{ p_fname }.jpg|
                                                filetype     = 'BIN'
                                                bin_filesize = xstrlen( lv_img_conv_data )
                                              CHANGING
                                                data_tab     = it_img_conv_data ).

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