Quantcast
Viewing all articles
Browse latest Browse all 68

File Upload/Download through NetWeaver Gateway

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.
1.jpg

 

2) Create an Entity type “File” (you can choose any name)

Image may be NSFW.
Clik here to view.
2.jpg

 

Create an Entity Set for the Entity Type by checking the check  box.

Image may be NSFW.
Clik here to view.
2.1.jpg

 

Mark Entity Type “File” as Media

Image may be NSFW.
Clik here to view.
2.2.jpg

 

3) Create one property “FileName” mark it as key and type as String

Image may be NSFW.
Clik here to view.
3.jpg

 

4) Generate run-time objects (or artifacts)

Image may be NSFW.
Clik here to view.
4.jpg

Image may be NSFW.
Clik here to view.
4.1.jpg

 

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.
5.jpg

 

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM for download file

Image may be NSFW.
Clik here to view.
5.1.jpg

 

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.
5.2.jpg

 

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.
5.3.jpg

 

6) Register the service & service is ready for use

Image may be NSFW.
Clik here to view.
6.1.jpg

 

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.
7.jpg

 

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.
8.jpg

 

File got updated in Z table

Image may be NSFW.
Clik here to view.
8.1.jpg

 

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.
8.2.jpg

 

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.


Viewing all articles
Browse latest Browse all 68

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>