Intro
This short instruction explains all the components which are used for displaying media data based on an oData service and an SAP UI5 application.
Step-by-Step
Service
- First you need an object, s.a. a image or a pdf document. Let’s call it Media Object.
- Then you need an oData service to deliver the data for the Media Object.
- Just create a plain oData service
- Create an entity type.
- Check the MEDIA check box for the entity type (oData Project->Data Model->Entity Types, double click your enttiy type, the attributes are shown on the right hand side)
- Switch to the …DPC_EXT class (oData Project->Runtime Artifacts)
- Use context menu->Goto ABAP Workbench
- Redefine the /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM method (see sample code Appendix)
- Once you want to call the media service you have to at the $value at the end of the query, e.g. <Service URL>/$value
SAP UI5
View:
<core:HTML id=“pdfContainer“ ></core:HTML>
Controller:
var oContainer = this.getView().byId(„pdfContainer“);
var oContent = „<iframe src='“+ <Service URL>/$value +“‚
+ „style=’width:600px; height:500px;‘ frameborder=’0′></iframe>“;
Transactions
Transaction | Explanation |
SEGW | SAP Gateway Service Builder |
Appendix
METHOD /iwbep/if_mgw_appl_srv_runtime~get_stream.
DATA:
ld_mypdf TYPE xstring,
ls_stream TYPE ty_s_media_resource,
ls_header TYPE ihttpnvp.
* Create the media data
* ld_mypdf = ...
* Set the MIME type and the value and create data ref
ls_stream-mime_type = 'application/pdf'.
ls_stream-value = ld_mypdf.
copy_data_to_ref(
EXPORTING is_data = ls_stream
CHANGING cr_data = er_stream ).
* In order to display the media data in place you have to set the
* following
ls_header-name = 'content-disposition'.
ls_header-value = 'inline; filename=MyPDF.pdf'.
/iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).