Here I will explain file handing in NW Gateway in few simple steps.
1) Create a NetWeaver Gateway project in SEGW.
2) Create an Entity type “File” (you can choose any name)
Create an Entity Set for the Entity Type by checking the check box.
Mark Entity Type “File” as Media
3) Create one property “FileName” mark it as key and type as String
4) Generate run-time objects (or artifacts)
5) Go to data provider extension class in edit mode and redefine method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM and
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~UPDATE_STREAM. Then add below code.
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM for download file
DATA: ls_stream TYPE ty_s_media_resource,
ls_upld TYPE zzupld.
READ TABLE it_key_tab ASSIGNING FIELD-SYMBOL(<fs_key>) INDEX 1.
DATA: lv_filename TYPE char30.
lv_filename = <fs_key>-value.
SELECT SINGLE * FROM zzupld INTO ls_upld WHERE filename = lv_filename.
IF ls_upld IS NOT INITIAL.
ls_stream-value = ls_upld-value.
ls_stream-mime_type = ls_upld-mimetype.
copy_data_to_ref( EXPORTING is_data = ls_stream
CHANGING cr_data = er_stream ).
ENDIF.
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~UPDATE_STREAM for upload file
DATA: lw_file TYPE zzupld.
READ TABLE it_key_tab ASSIGNING FIELD-SYMBOL(<fs_key>) INDEX 1.
lw_file-filename = <fs_key>-value.
lw_file-value = is_media_resource-value.
lw_file-mimetype = is_media_resource-mime_type.
lw_file-sydate = sy-datum.
lw_file-sytime = sy-uzeit.
MODIFY zzupld FROM lw_file.
I have created a Z table ZZUPLD to store/extract the file
6) Register the service & service is ready for use
7) Test the service from GW client. Upload the file into the Z table and extract it.
/sap/opu/odata/sap/ZDEMO_FILE_SRV/FileSet(lor.jpg)/$value
8) Browse your local file system and select your file. Once you upload the file SAP with automatically change the HTTP method as PUT . Execute the method. lor.jpg file got uploaded with ~status_code = 204.
File got updated in Z table
9) To download the file, just change the HTTP method to GET and execute. Program will read the existing file from the Z table as per FileName.
Here we are passing lor.jpg so GET operation will download the file we uploaded in Z table.
Similarly you can upload any file type to the Z table and can download them. In my next blog I will upload files from my UI5 application.