yourclass_MPC_EXT->DEFINE( )
METHOD define. super->define( ). DATA: lo_entity TYPE REF TO /iwbep/if_mgw_odata_entity_typ, lo_property TYPE REF TO /iwbep/if_mgw_odata_property. lo_entity = model->get_entity_type( iv_entity_name = 'UserPhoto' ). IF lo_entity IS BOUND. lo_property = lo_entity->get_property( iv_property_name = 'Mimetype' ). lo_property->set_as_content_type( ). ENDIF. ENDMETHOD.
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM( )
METHOD /iwbep/if_mgw_appl_srv_runtime~create_stream. DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair, lt_key_tab TYPE /iwbep/t_mgw_name_value_pair, ls_photo TYPE zsa_photos, lv_email TYPE char100. CASE iv_entity_name. WHEN 'UserPhoto'. READ TABLE it_key_tab WITH KEY name = 'Email' INTO ls_key_tab. ls_photo-email = ls_key_tab-value. ls_photo-mimetype = is_media_resource-mime_type. ls_photo-filename = iv_slug. ls_photo-content = is_media_resource-value. DELETE FROM zsa_photos WHERE email = ls_photo-email. INSERT INTO zsa_photos VALUES ls_photo. userphotoset_get_entity( EXPORTING iv_entity_name = iv_entity_name iv_entity_set_name = iv_entity_set_name iv_source_name = iv_source_name it_key_tab = it_key_tab it_navigation_path = it_navigation_path IMPORTING er_entity = ls_photo ). copy_data_to_ref( EXPORTING is_data = ls_photo CHANGING cr_data = er_entity ). ENDCASE. ENDMETHOD.
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM()
METHOD /iwbep/if_mgw_appl_srv_runtime~get_stream. DATA: ls_key TYPE /iwbep/s_mgw_name_value_pair, lv_email TYPE char100, ls_photo TYPE zsa_photos, ls_lheader TYPE ihttpnvp, ls_stream TYPE ty_s_media_resource, lv_filename TYPE string. CASE iv_entity_name. WHEN 'UserPhoto'. READ TABLE it_key_tab WITH KEY name = 'Email' INTO ls_key. lv_email = ls_key-value. SELECT SINGLE * FROM zsa_photos INTO CORRESPONDING FIELDS OF ls_photo WHERE email = lv_email. ls_stream-value = ls_photo-content. ls_stream-mime_type = ls_photo-mimetype. lv_filename = ls_photo-filename. lv_filename = escape( val = lv_filename format = cl_abap_format=>e_url ). ls_lheader-name = 'Content-Disposition'. ls_lheader-value = 'inline; filename="'. CONCATENATE ls_lheader-value lv_filename INTO ls_lheader-value. CONCATENATE ls_lheader-value '"' INTO ls_lheader-value. set_header( is_header = ls_lheader ). copy_data_to_ref( EXPORTING is_data = ls_stream CHANGING cr_data = er_stream ). ENDCASE. ENDMETHOD.