Skip to Content

Here I will explain file handing in NW Gateway in few simple steps.

1) Create a NetWeaver Gateway project in SEGW.

/wp-content/uploads/2014/09/1_546801.jpg

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

/wp-content/uploads/2014/09/2_546739.jpg

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

/wp-content/uploads/2014/09/2_1_546785.jpg

Mark Entity Type “File” as Media

/wp-content/uploads/2014/09/2_2_546786.jpg

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

/wp-content/uploads/2014/09/3_546787.jpg

4) Generate run-time objects (or artifacts)

/wp-content/uploads/2014/09/4_546788.jpg

/wp-content/uploads/2014/09/4_1_546789.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.

/wp-content/uploads/2014/09/5_546790.jpg

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM for download file

/wp-content/uploads/2014/09/5_1_546791.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

/wp-content/uploads/2014/09/5_2_546792.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

/wp-content/uploads/2014/09/5_3_546793.jpg

6) Register the service & service is ready for use

/wp-content/uploads/2014/09/6_1_546794.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

/wp-content/uploads/2014/09/7_546795.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.

/wp-content/uploads/2014/09/8_546798.jpg

File got updated in Z table

/wp-content/uploads/2014/09/8_1_546799.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.

/wp-content/uploads/2014/09/8_2_546800.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.

To report this post you need to login first.

33 Comments

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

  1. rajeesh o

    READ TABLE it_key_tab ASSIGNING FIELD-SYMBOL(<fs_key>) INDEX 1.


    replace above code with below code.

    FIELD-SYMBOLS:<fs_key> TYPE /IWBEP/S_MGW_NAME_VALUE_PAIR.

    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

    Regards

    (0) 
    1. Amaresh Pani Post author

      Thanks Rajesh. 

      READ TABLE it_key_tab ASSIGNING FIELD-SYMBOL(<fs_key>) INDEX 1.

      Is inline data declaration. From ABAP 7.4 onward it would work fine.  

      (0) 
  2. Siva prasad Ramani

    Hi,

     

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

    /wp-content/uploads/2014/12/pp_615426.png

     

     

     

    and my update_stream method not triggering.

     

    Here is my Entity type and its properties.

    /wp-content/uploads/2014/12/p3_615376.png/wp-content/uploads/2014/12/p2_615425.png

     

    Please check it once and help me.

    (0) 
    1. Amaresh Pani Post author

      Hi Siva – You need to contact your Basis team, they will update virus scan profile then it should work. Our basis team fixed it for me. If you have proper authorization then follow the steps here: http://help.sap.com/saphelp_nw70/helpdata/en/ee/50773f12f14a18e10000000a114084/content.htm?frameset=/en/f1/62eb4172fcc417e10000000a155106/frameset.htm&current_toc=/en/ae/ad1640033ae569e10000000a155106/plain.htm&node_id=89

       

      Amaresh Pani

      (0) 
      1. Siva prasad Ramani

        Hi.

        I activated virus scan profile.

        Still unable to upload photo in gateway service and getting this error.

        It says incorrect configuration for profile /SCMS/KPRO_CREATE.

         

        /wp-content/uploads/2014/12/gate_issue1_616970.png

         

        Regards.

        Siva R.

        (0) 
            1. Siva prasad Ramani

              Hi Amaresh,

               

              I’m struggling when create file in service.

              Please check it once.

              This is my Entity type and Entity set in my service.

              /wp-content/uploads/2015/02/q1_639679.png

              This is my DEFINE method.

              /wp-content/uploads/2015/02/q2_639752.png

              And here is my create_stream method.

              /wp-content/uploads/2015/02/q3_639753.png

              So when i add selected service I’m getting this warning.

              /wp-content/uploads/2015/02/q4_639754.png

              And when click on EntitySets, displays this information message.

              /wp-content/uploads/2015/02/q5_639755.png

              If i use Define method getting warning “Service was created but meta data could not be loaded” when add service.

              Problem there is in DEFINE method i guess.

              How can i resolve it.?

               

              Thanks,

              Siva R.

              (0) 
  3. Zhiyu Cao

    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:

    update_stream.JPG

     

    It says:’The server is refusing to process the request because the entity has an unsupported format’…….how 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?

     

    Thanks!!!

     

    Regards

    Cao

    (0) 
    1. Amaresh Pani Post author

      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?

       

      Capture.JPG

      With Regards

      Amaresh Pani

      (0) 
        1. Amaresh Pani Post author

          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

          (0) 
            1. Amaresh Pani Post author

              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

              (0) 
              1. Zhiyu Cao

                hi,Amaresh:


                Thank you very much for your helpful suggestions.

                 

                I have been uploaded my excel into internal table successfully.

                 

                Regards,

                Zhiyu

                (0) 
                1. Syambabu Allu

                  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

                   

                  Thanks,

                  Syam

                  (0) 
  4. siva krishna

    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.

     

    Thanks,

    SK

    (0) 
  5. Priya Kamath

    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.

    (0) 
  6. Laxman Chittepu

    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.

     

    Thanks,

    Laxman

    (0) 
  7. Ram G

    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.

     

    /wp-content/uploads/2016/05/file_upload_png_947847.png

     

    Can you let me know what could be the issue?

     

    Thanks

    (0) 
  8. Dipak Asawale

    Hi Amaresh,

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

     

    Thanks

    (0) 
  9. Arpitha Karuna

    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.

     

    Regards,

    Arpitha

    (0) 
  10. AJAY GUPTA

    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.

    (0) 
  11. Abdu Rahman

    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

    (0) 
  12. MUTHU KUMARAN

    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?

     

    Thanks,

    Muthu

     

     

     

     

    (0) 
  13. vinayreddy salibindla

    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.

    <mvc:View
    controllerName=”namespace.controller.fileup_View1″
    xmlns:html=”http://www.w3.org/1999/xhtml”
    xmlns:l=”sap.ui.layout”
    xmlns:mvc=”sap.ui.core.mvc”
    xmlns=”sap.m”
    xmlns:u=”sap.ui.unified”>
     <App>
      <pages>
       <Page title=”{i18n>title}”>
        <content>
         <l:VerticalLayout>
          <u:FileUploader id=”fileUploader”
          name=”myFileUpload”
          tooltip=”Upload your file to the local server”
          uploadComplete=”handleUploadComplete”
          uploadUrl=”upload/” width=”400px”/>
          <Button press=”handleUploadPress” text=”Upload File”/>
         </l:VerticalLayout>
        </content>
       </Page>
      </pages>
     </App>
    </mvc:View>

     

    (0) 
  14. patro srinivas

    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 shreenivaspatro@gmail.com

    Thanks in advance

    (0) 

Leave a Reply