Skip to Content

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.


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





DATA: ls_stream  TYPE ty_s_media_resource,

              ls_upld    TYPE zzupld.


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




DATA: lw_file TYPE zzupld.


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.



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.

You must be Logged on to comment or reply to a post.

    replace above code with below code.


    READ TABLE it_key_tab ASSIGNING <fs_key> INDEX 1.

    also use this link to upload /sap/opu/odata/sap/ZDEMO_FILE_SRV/FileSet('lor.jpg')/$value

    it will work fine...thank you  Amaresh Pani


  • Hi,


    I have followed every step when click execute as you said that. I'm getting this error.





    and my update_stream method not triggering.


    Here is my Entity type and its properties.



    Please check it once and help me.

  • HI,Amaresh:

              I need to upload a excel by sap ui5 and I read your article.when I followed every step of your article says and meet this errors:



    It says:'The server is refusing to process the request because the entity has an unsupported format' to do with it?


    and I also want to ask for another questions....Just for my scenario,I look for many articles and references,some of that tell me that I need to use 'create_stream' or 'get_stream'.and what you says 'update_stream',Is there three above methods all can resolve my scenario?






    • Hi Zhiyu - How did you upload your file? Did you use "Add File" button from the left panel to upload your file as given below?



      With Regards

      Amaresh Pani

        • Hi Zhiyu - It works fine for me. Can you please send a screenshot with "Content-Type" visible on it. Just like my above screenshot. 


          Amaresh Pani

          • /
          • Hi Zhiyu - I see in both of your screens the URI is not correct. It should be exactly /sap/opu/odata/sap/Z_LIT_EQUIMAINT_SRV/FileSet('')/$value . /$value is missing. try it, it should solve your issue.


            Amaresh Pani

          • hi,Amaresh:

            Thank you very much for your helpful suggestions.


            I have been uploaded my excel into internal table successfully.




          • Hi Zhiyu/Amaresh,


            Could you please share your development thought on Excel upload into internal table.I also have the same requirement but i am not able to achieve.Which you got the error the same error i am getting




  • Hi Amaresh.


    Thanks a lot for creating the document. Can you guide on the below requirement.


    My requirement is to upload a PDF document from third part portal written in .net. The portal will create a signed PDF document and the same has to be stored in sap using GOS functionality.


    My approach is

    1. create a webservice using SEGW and consume the same in the portal.

    2. The portal will convert the PDF file to binary format along with mime type and sent back to gateway.

    3. This binary file will be attached to the GOS menu of the transaction.


    I am doubt in point 2. Can you help me on this.




  • Hi Amaresh,


    Thanks for creating the document. I am not able to download .xlsx, .docx formats. Can you assist me in downloading these formats to respective file formats?

    I are getting run time error as  'A character set conversion is not possible' while downloading.

  • Thanks  Amaresh, waiting for your next blog to upload files from ui5 application. The step by step screen shots have helped me lot.


    Hi Experts,


    Can you please share the code snippet to download the files using sap ui5. I'm able to upload/retrieve the file in the gateway server.




  • Hi Amaresh


    I am following this blog to upload image. I am getting this error: "The request URI is not valid. The segment before '$value' must be a Media Link Entry". Below is the screenshot.




    Can you let me know what could be the issue?



  • Hi Amaresh,


    I am consuming this gateway service in ui5 and trying to upload from ui5 app to ztable.content not updating. Why any idea?




  • Hi Amaresh,

    Could you pls post the blog for Uploadinng and downloading the Files from SAP UI5 application. We are eagerly waiting for it.



  • Hi Amaresh,


    Excellent document!! This made my work so easy that I finished it in few moments.

    And you please share the same with UI5 application.




  • Amareesh - Thanks for a very informative blog. Could you please provide the link of  your next blog where you will link it to a sapui5 application.

  • Hi,

    I am getting an error while uploading...

    Call of service /sap/opu/odata/sap/Myservice/AttachmentsSet terminated because of an error. The following error text was processed in system dGW : Field symbol has not been assigned yet.The error occurred on the application server dgw. The termination type was: RABAX_STATE.If the termination type is RABAX_STATE, you will find more information on the cause of termination in system DGW in transaction ST22. If the termination type is ABORT_MESSAGE_STATE, you will find more information on the cause of termination on the application server vdgw in transaction SM21. If the termination type is ERROR_MESSAGE_STATE, you can search for further information in the trace file for the work process in transaction ST11 on the application server vdgw. You may also need to analyze the trace files of other work processes. If you do not yet have a user ID, contact your system adminmistrator.

    Please help to resolve this issue..

    Thanks & Regards

  • Hi,

    I got an error like "Invalid Key predicate",

    when using below URL:  /sap/opu/odata/SAP/ZUPLOAD_FILE_SRV/fileUploadSet('thor.jpg')/$value

    then i changed to /sap/opu/odata/SAP/ZUPLOAD_FILE_SRV/fileUploadSet('thor.jpeg')/$value, it works fine.

    It is basically checking the file format also?








  • Hi, As I am new to sapui5 technology i got a requirement that from the ui5 screen i need to upload a file to backend i,e oData service.

    all the different files with different extensions should be added when i perform upload operation from front end.

    here is the odata service url:    /sap/opu/odata/sap/ZOD_FILEATTACH_CRUD_SRV/fileSet(‘TextFileUpload’)/$value

    so please guys do help me.If any one good at sapui5.

       <Page title="{i18n>title}">
          <u:FileUploader id="fileUploader"
          tooltip="Upload your file to the local server"
          uploadUrl="upload/" width="400px"/>
          <Button press="handleUploadPress" text="Upload File"/>


  • Hi ,that's a great document. I have a doubt..why you used http PUT method for uploading? cann't we use POST method? if not can u please mention the reason.I am searching for days but i didn't get solution. and Could you please post the blog for Uploading and downloading the Files from SAP UI5 application??? please share any updates at

    Thanks in advance

  • /
  • A Wonderful post,

    Just with one correction in calling get_stream / update_stream we need to pass the filename in single quotes.



    Thanks a lot

  • Hi

    I have an issue to retrieve image file. Its not return in image file. I had follow all the steps as well as in SEGW, type Edm.Guid and entity type is tick as media. When I click GET it returns to error 'Malformed URI literal syntax'. Below screenshot is when I click ADD FILE.

    Please help me on this.





  • Hi,

    I am trying to store XML file as Xstring and trying to get it through get_stream method. But its not showing the file in Gateway client. Can we store XML file also in Xstring in Database and get it through get_stream?