Mentor SAP

Media Links

Media links display, create, modify, and delete binary files. The following are examples of media links:

 

Media Links — Direct Content Link (read-only)

To redefine the model, perform the following steps:

 

Fill the mapped attributes with the following data:

 

Sample HTTP Response…/SAP/PUBLIC/BC/NWDEMO/IMAGES/HT-1040.jpg

The following is an example of HTTP Response for …/SAP/PUBLIC/BC/NWDEMO/IMAGES/HT-1040.jpg

<entry>
<link href="Products('HT-1040')" rel="edit" title="Product"/>
<link href="Products('HT-1040')/$value" rel="edit-media"
type="image/jpeg"/>
<content type="image/jpeg"
src="/SAP/PUBLIC/BC/NWDEMO/IMAGES/HT-1040.jpg"/>
<m:properties>
<d:ProductID>HT-1040</d:ProductID>
<d:Category>Laser printers</d:Category>
<d:Name>Laser Professional Eco</d:Name>
<d:Description>…</d:Description>
<d:ProductPicUrl>/SAP/PUBLIC/BC/NWDEMO/IMAGES/HT-1040.jpg
</d:ProductPicUrl>
<d:ProductPicUrlMimeType>image/jpeg</d:ProductPicUrlMimeType>
</m:properties>
</entry>

ProductPicUrl is provided if an external link is used. The content type contains the mime type, which is also used as a header in the response header if $value has been called. There are two use cases:

 

In our example the field contains a relative link, src="/SAP/PUBLIC/BC/NWDEMO_MODEL/IMAGES/HT-1040.jpg, since the picture is stored in the local mime repository. In reality, you would use an external link that would point to the picture: src="http://mywebserver/images/"

 

Media Links – Redefine Direct Content Link

To redefine the define method of the Model Class xxx_MPC_EXT, use the following code

METHOD define.
DATA:
lo_entity   TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
lo_property TYPE REF TO /iwbep/if_mgw_odata_property.

super->define( ).
lo_entity = model->get_entity_type( iv_entity_name = 'Product' ).
lo_entity->set_is_media( ).
IF lo_entity IS BOUND.
lo_property = lo_entity->get_property(
iv_property_name = 'ProductPicUrl' ).
lo_property->set_as_content_source( ).
lo_property = lo_entity->get_property(
iv_property_name = 'ProductPicUrlMimeType' ).
lo_property->set_as_content_type( ).
ENDIF.
ENDMETHOD.

Media Links - Media by Streams

Instead of using a relative or absolute URL, media can also be accessed directly via SAP Gateway by using the $value option. For read access, for example, the GET_STREAM method has to be implemented. To implement this, perform the following steps:

  1. Set the entity media attribute to true: set_is_media( 'X' )
  2. Implement the following methods:
    • ~GET_STREAM
    • ~CREATE_STREAM
    • ~UPDATE_STREAM
    • ~DELETE_STREAM
  3. Fill the stream parameter based on the type: /iwbep/if_mgw_core_srv_runtime=>ty_s_media_resource

Sample GET…/Products(‘HT-1040’)/$value