Here I will explain file handing in NW Gateway in few simple steps.
1) Create a NetWeaver Gateway project in SEGW.
Image may be NSFW.
Clik here to view.
2) Create an Entity type “File” (you can choose any name)
Image may be NSFW.
Clik here to view.
Create an Entity Set for the Entity Type by checking the check box.
Image may be NSFW.
Clik here to view.
Mark Entity Type “File” as Media
Image may be NSFW.
Clik here to view.
3) Create one property “FileName” mark it as key and type as String
Image may be NSFW.
Clik here to view.
4) Generate run-time objects (or artifacts)
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
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.
Image may be NSFW.
Clik here to view.
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM for download file
Image may be NSFW.
Clik here to view.
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
Image may be NSFW.
Clik here to view.
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
Image may be NSFW.
Clik here to view.
6) Register the service & service is ready for use
Image may be NSFW.
Clik here to view.
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
Image may be NSFW.
Clik here to view.
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.
Image may be NSFW.
Clik here to view.
File got updated in Z table
Image may be NSFW.
Clik here to view.
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.
Image may be NSFW.
Clik here to view.
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.