Skip to Content
Author's profile photo Former Member

How To Upload and Download Files Using SAP NW Gateway SP06

UPDATE JUNE 2014: Please note that in the blog below I create custom RFCs for this purpose which I would no longer recommend. As discussed in the comments made by Ron Sargeant to this blog and also in his own blog Improved Inside-Out Modelling where also Krishna Kishor Kammaje joins in the discussion a code based approach would have been a far more elegant solution than creating custom RFCs. I hope to update this blog with a code based implementation of the same sometime in the future.

The aim of this blog is to provide a step by step approach enabling anyone that needs a gateway service to upload/download files to SAP backend to develop it in no time.

In this blog I have listed some existing blogs and SCN posts regarding this topic. These have helped me manage to develop my upload/download service but none of them give a full step by step approach of how to do this and they refer to different versions of Gateway.

Note that in my examples the values contained in <> needs to be substituted with your own values šŸ˜‰

1. Create Table

First I created a table to contain the uploaded files with the following properties:

Capture.PNG

You can of course adjust these properties to your need but the mimetype and value (stored as rawstring) will always be needed.

2. Develop Function Modules

Two Remote Function Modules was then developed. One that can upload a file to the table above and one that downloads from it.

The upload RFC has these import parameters and simply dumps the input into the table:

Capture.PNG

The download RFC takes the key values PERNR and FILENAME as input and exports:

Capture.PNG

It simply executes a read on the table using the key values and sets the export parameters.

Remember to mark the function modules as remote enabled šŸ™‚

3. Create Project in SEGW and Entity Types

A project was created in SEGW and an entity type based on the download function module (right click Data Model->Import->RFC/BOR interface) created giving the properties as shown below:

Capture.PNG

On the actual entity, that I have called “File”, it is important to tick the Media option as shown:

Capture.PNG

Setting a data object as media type means that it gets a special semantic by having a URL and allows streaming etc. This then sets the property hasStream to true in the service document as can be seen when issuing a $metadata request to the service:

Capture.PNG

Furthermore in the model provider class <classname>_MPC this line of code is dynamically added: lo_entity_type->set_is_media(‘X’ ).

For a further description of the Media property see also: http://help.sap.com/saphelp_gateway20sp04/helpdata/en/67/d2c38221984d8eb46b8a8d983407b9/content.htm

Lastly an entity set based on the entity needs to be created,

4. Create Upload Service

To create the actual service simply look in the “Service Implementation” folder and right click the “Create” operation and select “Map to Data Source”. Select the function module you use for uploading files. Do the same for the “GetEntity (Read)” operation but of course based on the download RFC. Use the “Propose Mapping” functionality to map the parameters. You should end up with mappings similar to this:

Capture.PNG

Capture1.PNG

5. Redefinitions

For the services to work some manual coding also needs to be done. This is done through redefinitions of the standard methods on the classes <classname>DPC_EXT and <classname>MPC_EXT. You locate these in the “Runtime Artifacts” folder. They are opened by right clicking them and choosing “Go to ABAP Workbench”. The methods are then redefined by right clicking them and choosing “Redefine” – all pretty simple šŸ˜‰

A total of three redefinitions was done and I will describe them below:

A – Marking Mime Type  

When entity type has been marked as media (as described in step 3) we also have to mark which of the entity properties that holds the mime type of the object. This needs to be done programmatically by redefining the method DEFINE of the model provider class <classname>_MPC_EXT.

Code is inserted to mark one of the entity type properties as Content type i.e. the property that represents mime type information. You can get the the code snippet that you can adapt to your case here SAP NetWeaver Gateway Service Builder: How to Read Photo – Code Snippets which is from Rashmi BR excellent blog that you can find here How to Read Photo from SAP system using SAP Gateway

B – Redefining CREATE_STREAM

To support the upload of files the method CREATE_STREAM needs to be redefined in class <classname>_DPC_EXT. All the needed parameters are available in the redefined method. First the filename or other key parameter can be retrieved through import parameter iv_slug:

Capture.PNG

The actual uploaded media and mime type parameter is contained in import parameter is_media_resource:

Capture1.PNG

Capture2.PNG

GET_ENTITY is the used to perform a read and then the parameters can be copied to the request through standard method COPY_DATA_TO_REF :

20140127 Updated code below to perform correct read after upload.

Capture.JPG

  

C – Redefining GET_STREAM

To support the downloading of files the method GET_STREAM needs to be redefined in class <classname>_DPC_EXT. All the needed parameters are already available here. First the key parameters are retrieved. In example below it is “Pernr” that is retrieved but “Filename” is also retrieved the same way as it is part of the key in this example:

Capture.PNG

Then the file download is requested and the stream and mime type is copied to export parameter using standard data type ty_s_media_resouce through standard method COPY_DATA_TO_REF:

Capture.PNG

6. Running the Services

To test the Create and Read services the following calls can be executed:

A – Create

To run my example you perform a HTTP POST to a URL like this: host:port/sap/opu/odata/sap/<servicename>/Files

You can use the built in Gateway Client tool to test the service. You execute the client tool from /iwfnd/maint_service and then in the tool you can use the “Add File” button to add a file to the POST request and the + button to add headers to the post request.

In the post command you need to add the headers “Content-Type” and “slug”. For example for PDFs content type should be “application/pdf” and slug needs to contain the key – in my case filename. Note that if you use Gateway client tool you don’t have to supply content type parameter.

NOTE: If you are not using the Gateway client test tool you also need to remember to add the X-CSRF-Token in the header of the post command. You can get the token by issuing a GET to the service with the header=x-csrf-token and value=fetch. You will then be able to read the token in the response and can supply it in the POST.

On successful POST the document is stored in the database table and you get some xml response back.

PROBLEM: in my response I’m missing the keys of the just uploaded document as shown below. So I guess I’m doing something wrong in my implementation of CREATE_STREAM as described in 5.C. Has anyone got some hints for me to solve this?

Capture.PNG

Note that in my example the Personnel number and creation Date are automatically retrieved by the service implementation so doesn’t need to be supplied in the post.

B – Read

To read information about the uploaded files a GET containing the keys – in my case “Pernr” and “Filename” – can
be issued like this: host:port/sap/opu/odata/sap/<servicename>/Files(Pernr='<pernr>’,Filename='<filename>‘)

In the response you will then be able to see that the actual document can be retrieved/downloaded by adding /$value to the request above for example:

host:port/sap/opu/odata/sap/<servicename>/Files(Pernr='<pernr>’,Filename='<filename>‘)/$value

Conclusion

I have written these services to the best of my knowledge but I’m very interested in getting feedback and possible improvement points.

References:

Blogs:

Gateway Service using the OData Channel Approach (ABAP Coding)  for Media Links(Photo,Document) by arun chembra

How to Read Photo from SAP system using SAP Gateway

Media Links – SAP Documentation

SCN Posts:

Re: Upload File with parameters?

File Attachment using gateway

FileUploader and X-CSRF-Token?

Assigned Tags

      95 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Arun Chembra
      Arun Chembra

      nice...

      Author's profile photo Former Member
      Former Member

      Good one..

      Author's profile photo Kartik Natarajan
      Kartik Natarajan

      Thanks for sharing Jan,

      regards

      kartik

      Author's profile photo Former Member
      Former Member

      Good stuff. We should remember that for a live implementation the virus scanning option is most likely to be required; not many security administrators are going to let unscanned files into the backend.  

      Regards

      Ron.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Ron, can you refer to a document/blog describing the approach for this?

      Author's profile photo Former Member
      Former Member

      Hi Jan Thomas,

      first i want to thank for the great post, which is very useful.

      i'm facing an issue while following the above process because in my scenario i'm creating RFC(Function modules & table in ECC-Backend) and i'm creating oData service in Netweaver Gateway-Frontend.

      i have followed your code snippet for Display Image Its working fine.

      SAP NetWeaver Gateway Service Builder: How to Read Photo - Code Snippets


      error1.PNG

      In the same way i'm trying for upload image in Create stream method.(In the above link i dont find code for Create Stream)


      So for that im calling Create_Entity method in Create_Stream method.


      error2.PNG


      But while calling the method its going into Exception.


      My Question is.

      1. Is it the correct way to do?

      2. If correct can i pass IO_DATA_PROVIDER or Not

      3. If i don't pass the data also its going into Error & If I pass also its going into exception.


      For this i have followed another way i have copied code from Create_Entity method and passing the value here manually.I dont think this is correct way to do it.

      error3.PNG

      Now the Image is uploading in Table but in showing an error in Gateway Client.

      error4.PNG

       

        <?xml version="1.0" encoding="utf-8" ?>

      - <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

        <code>005056A509B11ED1B9BF9F46AA8E82ED</code>

        <message xml:lang="en">In the context of Data Services an unknown internal server error occured</message>

      - <innererror xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

        <transactionid>558586FF9F09249BE1000000AC190A66</transactionid>

        <timestamp>20150623095848.9848970</timestamp>

      - <Error_Resolution>

        <SAP_Transaction>Run transaction /IWFND/ERROR_LOG on SAP NW Gateway hub system and search for entries with the timestamp above for more details</SAP_Transaction>

        <SAP_Note>See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)</SAP_Note>

        </Error_Resolution>

        </innererror>

        </error>

      Any suggestions are highly appreciable.


      Thanks & Regards,

      Santhosh Reddy.

      Author's profile photo kumud ranjan jha
      kumud ranjan jha

      Hi Ron,

      I am facing an issue with downloading the file attached and saved in custom table, it would be of great help if it could get resolved with your help.

      I am trying to implement the same, upload was successful we were able to save the data in table.

      But while download getting some issue.

      On testing the download component using gateway client status code coming is 200 but in response I get statement written as

      "Click "Response in Browser" to display data in the right format."

      upon clicking response browser we get an error saying window photo viewer can not open this picture because either photo viewer doesn't support this file format (please find the error screenshot attached)

      note: we are running on SP04

      Requesting a positive response.

      image downloading.PNG

      on clicking response in browser we get error as shown below.

      error on clicking response in browser.PNG

      we tried with PDF format and JPEG format as well.

      but in both the cases we get error

      Error in PDF:

      Error in PDF download.PNG

      Author's profile photo Former Member
      Former Member

      Hi Kumud,

      Did you find any solution for this issue ?

      I am also facing a similar issue while trying the same for excel file. I am giving the file format as 'xlsx'. On click of 'Response in Browser' button in gateway client, i'm always getting an excel sheet with the first record only. (despite querying some other record).

      Author's profile photo Former Member
      Former Member

      Aha! No!

      The installation of a virus scanner, or it's location, etc are usually managed by Basis. So when it goes over to an environment where the scanner is mandatory, Basis have carried out that activity.

      The Help page for virus scanning is here: http://help.sap.com/saphelp_nw74/helpdata/en/b5/5d22518bc72214e10000000a44176d/content.htm?frameset=/en/6c/4f22518bc72214e10000000a44176d/frameset.htm

      In terms of the Gateway development, it should not require you to alter the code. The inbound request handling detects if a binary stream, such as a file attachment, is part of the request - it then invokes the virus scanner according to the scanning profile. In development we tend to simply turn it off for convenience.

      regards

      Ron.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Yes I've turned it off in our development environment as well but know this is an area we have to look at for production. Worst case in our scenario is that a user opens a document from SAP that includes a virus and it should then be caught by virus software on the PC.

      Author's profile photo Former Member
      Former Member

      Jan, I believe this will solve the problem you have stated.

      PROBLEM: in my response I'm missing the keys of the just uploaded document as shown below. So I guess I'm doing something wrong in my implementation of CREATE_STREAM as described in 5.C. Has anyone got some hints for me to solve this?

         At the end of CREATE_STREAM you need to do a GET_ENTITY and pass it to ER_ENTITY.

      For reference, look towards the end of any of the CREATE_ENTITY method .

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Yes that fixed the issue šŸ™‚

      Looking at it now I actually realize that I was copying the stream back into the response which was also not very wise from a performance perspective. I will update the blog.

      Thanks Ramprasad

      Author's profile photo Former Member
      Former Member

      Your welcome Jan, glad I could add something to your blog.

      Author's profile photo Former Member
      Former Member

      Hi Ramprasad,

      I have created this example and it is working fine.. For you suggestion to send back key fields.. how we can call get_entity after create_stream.. I am using Transaction SEGW.

      Please share the code

      Regards

      Author's profile photo Former Member
      Former Member

         *-------------------------------------------------------------------------*
      *             - Read After Create -
      *-------------------------------------------------------------------------*
        data lo_tech_read_request_context type ref to /iwbep/cl_sb_gen_read_aftr_crt.
        create object lo_tech_read_request_context.

      * Create key table for the read operation
        data ls_key type /iwbep/s_mgw_tech_pair.
        data lt_keys type /iwbep/t_mgw_tech_pairs.

        ls_key-name = <>

        ls_key-value = <>.
          append ls_key to lt_keys.

      * Set into request context object the key table and the entity set name
        lo_tech_read_request_context->set_keys( importing et_keys = lt_keys ).

        data lv_entityset_name type string.
        lv_entityset_name = io_tech_request_context->get_entity_set_name( ).
        lo_tech_read_request_context->set_entityset_name( importing ev_entityset_name = lv_entityset_name ).

        data ls_entity type ref to data.
      * Call read after create
        /iwbep/if_mgw_appl_srv_runtime~get_entity(
          exporting
            iv_entity_name     = iv_entity_name
            iv_entity_set_name = iv_entity_set_name
            iv_source_name     = iv_source_name
            it_key_tab         = it_key_tab
            io_tech_request_context = lo_tech_read_request_context
            it_navigation_path = it_navigation_path
          importing
            er_entity          = ls_entity ).

        field-symbols: <ls_data> type any.
      * Send the read response to the caller interface
        assign ls_entity->* to <ls_data>.

        copy_data_to_ref( exporting is_data = <ls_data>
                          changing  cr_data = er_entity ).

      Author's profile photo Former Member
      Former Member

      Hello RamPrasad,

      When i tried ur code, i could not see the key name and values passed to IT_key_tab.

      where and what could have wrong ? any idea ?

      Author's profile photo Former Member
      Former Member

      HI Nitin,

      Internal table will be having 2 fields. one is key and another is value.

      The internal table will capture the value based on which method you have implemented and which method you have called.

      Thanks.

      Akshath

      Author's profile photo Carlos Dias
      Carlos Dias

      Hi Jan,

      thank for your initiative šŸ™‚ I'm trying to implement your upload/download services but i'm coming from a javascript/java world and ABAP is new stuff for me. However i know how SEGW and OData work.

      Can please give more detail about the methods redefinition? Especially for case B and C. Because i'm a bit lost trying to redefine the methods. For example: find the value for pernr to call the previously created RFC.

      Thanks a lot!

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      I get pernr like this:

      call function 'HR_GETEMPLOYEEDATA_FROMUSER'

          exporting

            username                        = sy-uname

      *     VALIDBEGIN                      = SY-DATUM

         importing

           employeenumber                  = ls_catsrecords_in-employeenumber.

      *     COUNTRYGROUPING                 = "use country group to restrict access for other countrie

           "name                            = emp_name.

      I can mail you some more code but then I think you need to "follow" me so that we can connect šŸ™‚

      Author's profile photo Carlos Dias
      Carlos Dias

      Thank you for your code.

      I'm "following" you šŸ™‚ Can you see my email?

      Author's profile photo Ravi Varma Indukuri
      Ravi Varma Indukuri

      Hi Jan Thomas Nygaard

      I am very new to sap net weaver gateway and got a requirement on how to upload a file through gate way service and have created table as mentioned in document but i am bit confuse while implementing zfunction module.

      I went through standard service RMTSAMPLEFLIGHT, got sucessfuly downloaded file.

      I am following you, Could you please provide the code in Function Module(Upload),

      Thanks in advance

      Ravi varma

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Ravi,

      If you connect with me I think I can send it to you.

      Author's profile photo Ravi Varma Indukuri
      Ravi Varma Indukuri

      Hi Jan Thomas,

      How can we connect Can you see my email?

      mail ID: svs2020.com@gmail.com

      Thanks in Advance

      Ravi varma

      Author's profile photo Ravi Varma Indukuri
      Ravi Varma Indukuri

      Hi Thomos,

      Actually i am using net weaver version is 731(IW_BEP -->SP-006) it does'nt have add file option in gateway client,

      when i am trying to create(POST) the file into ztable via REST client (google chrome advanced version) getting error as file has unsupported format (415) error.

      URL for posting document is :/sap/opu/odata/sap/ZUPLOAD_DOCUMENT_SRV/uploade

      here uploade is my entity set name

      I am attaching you the screenshots which i got in rest client

      so Could you please guide me on this...

      Responce:

      rest.PNG

      Input:responce.PNG

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      not sure - which media type are you trying to submit?

      check log files as listed here

      http://scn.sap.com/community/netweaver-gateway/blog/2013/03/26/netweaver-gateway-t-code-summary

      Author's profile photo Ravi Varma Indukuri
      Ravi Varma Indukuri

      I am trying to POST application/pdf and images for both i am getting same error as

      Unsupported Media File Format'

      I don't understand where am wrong..

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Ravi,

      First try to see if you can get the post command to work in the built in netweaver gateway test client. In there you don't have to worry about the token. Can you get that to work?

      From your POST request above it looks like you are not supplying the x-csrf-token correctly. You get the token using a GET request with the fetch command. It looks like you are using fetch in the POST above. In the POST you supply the token key instead of the fetch command.

      BR Jan

      Author's profile photo gunjan ajmani
      gunjan ajmani

      Hi Jan

      Thanks for this wonderful blog. I was actually able to implement the file upload and download as you have mentioned. I would perhaps like to ask you and other experts if they could help me achieve a similar thing (file upload and  download) for multiple documents. i.e. I want to upload multiple PDF's into the SAP system through Netweaver Gateway. I tried out the Batch Processing methodology however through the gateway client i could process only one document at a time.If i try to upload multiple files the gateway client rejects the old one and processes the latest file.

      Any help in this regard will be highly appreciable. Thanks in advance. šŸ™‚

      Author's profile photo Ravi Varma Indukuri
      Ravi Varma Indukuri

      Hi gunjan,

      Can i know how did you get success in implementing file upload and downloading service in net weaver gateway, i did the same as jan mentioned in the blog but i got struck and getting error as

      "Unsupported Media File Format".

      if you help on this would be very appreciable.

      Thanks in advance,

      Ravi varma

      Author's profile photo gunjan ajmani
      gunjan ajmani

      Hi Ravi

      Could you please add a new header and send 'application/pdf' manually instead of the rest client adding that automatically. Also, please fetch an appropriate X-CSRF token and send that while performing the post.Lets hope if that works šŸ™‚

      Gunjan Ajmani

      Author's profile photo Prasanna Prabhu
      Prasanna Prabhu

      Hi All,

      I also have the requirement of file uploading in gateway. Currently am able to get the control to create stream method.

      Could you please help me out how can i read the details of the file and upload the file into the table.?

      Author's profile photo Former Member
      Former Member

      Hi,

      I am working on uploading file in SAP using NW. I am able to read the '.jpg' files and upate them using SEGW. Any how for POST am not getting value for other attributes of entity.. I am able to get file type and content in IS_MEDIA_RESOURCE.

      How can i get value for attributes defined for my entity type apart from media content.. Like in you example how we can get value for PERNR, File name & other attributes..

      Please assist..

      Regards

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Rajesh,

      For the post I think you only have the "slug" value to pass attribute information in. I use "slug" for the filename in my example. If you want to use it for more than 1 attribute I guess one method could be to define that first 10 characters are for pernr, next 10 for filename etc.

      In my case the file uploaded always belongs to the PERNR doing the upload action so I just retrive the PERNR from sy-uname in the CREATE_STREAM method usign function module HR_GETEMPLOYEEDATA_FROMUSER

      Br Jan

      Author's profile photo Former Member
      Former Member

      Thanks Jan for responding.. we can you slug and pass required values for CREATE_STREAM...

      One more question.. can we return multiple media files in one get request.. Like we do with Deep entity .. Header record with employee details and Item will have pictures...

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      I'm not sure but I'd be interested to know if and how you solve it. I have been playing around with a service to upload multiple files but without luck so far.

      Author's profile photo Former Member
      Former Member

      Well i am trying to explore more options.. It is working fine for .jpg, pdf and excel files.. But it excel file having formatted data it is throwing exceptions..

      "At the conversion of a text from codepage '4110' to codepage '4103':"

      Anyone faced the same issue.. Please assist.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Prasanna,

      My blog is about uploading a file into a table. Have you gone through the blog step by step? If so where exactly are you facing problems?

      Br Jan

      Author's profile photo Prasanna Prabhu
      Prasanna Prabhu

      Hi Jan,

      Thanks for the inputs.

      Yes i got it. I am able to upload the file.

      Regards

      Prasanna.

      Author's profile photo Syambabu Allu
      Syambabu Allu

      Hi Jan,

      Well written .Surely will try this and let you ask to qns if i have facing any issues.

      Thanks,

      Syam

      Author's profile photo Former Member
      Former Member

      Hi Jan ,

      I got a requirement on how to upload a file through gate way service and have created table as mentioned in document but i am bit confuse while implementing RFC for UPLOAD and DOWNLOAD ...


      Can you please share me your code  for UPLOAD and DOWNLOAD ...


      Mail to me [ (prashanth.ga1@gmail.com)  or at " primezest@gmail.com " ]

      your code so that I can follow accordingly .


      Thanks in advance,

      Prashanth



      Author's profile photo Former Member
      Former Member

      Custom RFC for Gateway? Eeeew. 😏

      I referred back to this yesterday as I was doing some file transfer work. I hadn't noticed the RFC bit! What's wrong with code based-implementation? If you've got to write code, might as well do it in the DPC implementation. Creating RFC just adds more obfuscation to a simple job.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Ron

      Thank you for your comment. I must admit I hadn't thought about that option. But I guess you are right - I could simply put the RFC code into the DPC_EXT classes to keep it simple.

      I'm used to using SAP standard RFCs to implement gateway services so when I needed custom code like in this example I thought about custom RFCs.

      I will consider this in future service implementations. Let me know if you have more thoughts on this.

      BR Jan

      Author's profile photo Former Member
      Former Member

      Hello Ron,

      I tried creating scenario explained by Jan.

      I get the error "No default virus profile active or found. Please check the offical guide".

      How to find out of several virus scan profiles which to choose ?

      Author's profile photo Former Member
      Former Member

      Hi Nitin,

      I'm guessing you don't want to "mess around" with virus scanning installation, so the easiest option is to turn it off.

      Go to SPRO: Gateway/Administration/General Settings/Virus Scan Profile.

      Execute and tick the 'Off' checkbox.

      Author's profile photo J Dinesh
      J Dinesh

      Hi Jan ,

      I got a requirement on how to upload a file through gate way service and have created table as mentioned in document but i am bit confuse while implementing RFC for UPLOAD.


      Can you please share me your code  for UPLOAD and DOWNLOAD ...


      Mail to me at dinesh.csetech@gmail.com

      your code so that I can follow accordingly .


      Thanks in advance,

      Dinesh

      Author's profile photo J Dinesh
      J Dinesh

      Hi Jan,

         My requirment is to upload PDF file from UI5 screen to SAP Back end server.

      Now I have created one RFC and a project in segw .

      But in segw project when i create service implimentation, it gives warnings like Mapping of Create operation without Read may cause an error at runtime.

      Since i am going to upload i only implimented create .

      Kindly help me here .

      Thanks  in advance.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi dinesh,

      The warning you get is becuase the gateway per default always issues a read after a create operation has been carried out.

      I suggest you implement the GetEntity operation as well to avoid this warning.

      Br Jan

      Author's profile photo Former Member
      Former Member

      HI,

      How can we upload those file in MIME repository ?

      My requirement is ==>

      I have upload file in SAP-UI5, those file should upload in MIME repository (SAP-ECC)back end.

      How can i do this? 

      Kindly help me on this...

      Author's profile photo Former Member
      Former Member

      Hi Akshath,

      you need to use the following code in RFC :
      1st . CALL FUNCTION 'GUI_UPLOAD'

      2nd. CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

      3rd.  Finally Store it in MIME repository using the

      lr_mime_rep = cl_mime_repository_api=>if_mr_api~get_api( ).

      lr_mime_rep->put(

      --

      --

      ).

      and then using this RFC ; set the mapping in SEGW as per your requirement to upload the file

      Thanks,

      Prashanth

      Author's profile photo Former Member
      Former Member

      Hi Prashanth,

      Right now i am using same for both upload/download. is this way is correct?

      Will read UI5 if i pass xstring/binary data as a Odata?

      Author's profile photo Former Member
      Former Member

      Hi Akshath

      Refer this link to : Display Smartform (PDF) in SAPUI5

      hope this helps

      Thanks,

      Prashanth

      Author's profile photo J Dinesh
      J Dinesh

      Hi Syam ,

                  Can u give the exact code to redefine GET_ENTITY in DPC_EXT

                 Code above is not working.

      Thanks in advance.

      Author's profile photo Former Member
      Former Member

      Hi,

      I have an entity which has other properties like created by, docCategory etc.

      But how can i pass the values of these parameters while testing my service from NW gateway client.

      I am using Post method and added a file. I don't want to include these other attributes in 'Slug' header. is there any other option ?

      Untitled.pngRegards,

      Rohit

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Rohit,

      I think your only option is to pass these values in the slug parameter. You can always do some key/value pairs and then have the logic to split them up in the code.

      Let me know if you find a different way to achieve this.

      Br Jan

      Author's profile photo Former Member
      Former Member

      Hi Jan ,

      Can explain more detailed on the code you posted above regarding " code below to perform correct read after upload. "download.JPG

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Prashanth,

      As far as I know this code is pretty standard to perform a read. You can see similar code being auto generated in the DPC classes when you implement a standard GET_Entity/Read method.

      What exactly is causing you problems?

      Br Jan

      Author's profile photo Former Member
      Former Member

      Hey Jan,

      first...thanks for the sharing of your idea and thoughts.

      But i am still encountering problems.

      i've managed to create the table, the rfc's an the gateway service including the mapping.

      But my ABAP-Skills aren't that good to know, how to change the code to my needs.

      i want to consume pdf's or any other file through a ui5 application. Download or just viewing.

      can you send me the code for reading a stream and marking it as a mime type?

      my mail is volkan.adiguezel@gmail.com

      Author's profile photo Former Member
      Former Member

      Thanks Volkan for the valuable suggestion. now it is not throwing that error. other errors are there, i m trying to solve it.

      thanks a lot for saving my time and efforts.

      Author's profile photo Velsankar Sundareswaramoorthy
      Velsankar Sundareswaramoorthy

      Hi Jan,

                 A nice one. Can you send me the code snippets. I am following you

      Author's profile photo Vijay Vegesana
      Vijay Vegesana

      Hello Jan,

      Thanks for the blog,

      Need some lights on,what is the maximum file size that can be uploaded as a Image from the front end.

      I am getting error code 3 as a server response while uploading the image in Phone Gap..

      Thanks,

      Vijay V

      Author's profile photo Arshad Ansary
      Arshad Ansary

      Hi Jan,

      Thanks for the excellent blog .

      I have a requirement to download the content which is shown in the UI5 screen to presentation server (on click of buttton in Ui5).

      Can Ui5 sent the table content in screen  via is_media_resource-value?. In addition they need to send the path for the file to be downloaded ,type of file to be downloaded(CSV or PDF) ,Which appln file (with this I know the structure/Table type  to write the file content).

      I am planning to have entity type File with all these properties and the UI can trigger a PUT with all these properties from the URL and read theser URL key values and is_media_resource-value in the update stream method of DPC class .Then call generic backend FM  to download to presentation server

      Is this the right approach?

      Regards

      Arshad

      Author's profile photo Former Member
      Former Member

      Hi Arshad,

      Your terminology is wrong here. You do not communicate with the "presentation server" to obtain content, that would be your content server, and in since we are in the Gateway space (not UI5), let's assume it's GW.

      Physically, UI5 and GW may be on the same server but they are reached by separate ICF nodes.

      Having got that out of the way, you need to explain what your actual content is more clearly than just 'table'.

      If it is just tabular data, then it should not be treated as a file if it did not originate as a file. It's typically an entity collection.

      The use case you are attempting might be valid if the application did something like opening an Excel file in the UI5 frontend and presenting the content in a non-Excel way. You might then decide that the file should be saved to the content server so that it can be reloaded elsewhere into the UI5 app, i.e. not reliant on the original local PC copy. Even then there is a case for transforming it into an OData entity instead. 

      Regards

      Ron.

      Author's profile photo Arshad Ansary
      Arshad Ansary

      Hi Ron,

      My requirement is simple . On click of 'download' button it should download the tabular content(Shown in UI5 ) as  CSV file to users desktop  .

      If i model it as an Entity type , then only CRUD operations are supported.How do I model a download operation for an Entity type ? Do I need additional properties(File Path,File Type etc) in all these Entity types where download is required?

      Even if I model it as a Fx import, can they  send a request body(data to be downloaded) with the Fx import ? May be POST Fx import?

      Regards

      Arshad

      Author's profile photo Former Member
      Former Member

      Hi Arshad,

      In that case your terminology is even further off. And you are in the wrong Space. šŸ™

      If you want to save data to the PC (presentation client, local) you cannot achieve this with Gateway. GW is about backend service communication, not local services.

      This would be completely the duty of the UI5 application, also running on the local presentation client - most likely achieved by javascripting (ugh!).

      Please redirect this question to the correct SCN Space for a better hope of getting an answer.

      Regards

      Ron.

      Author's profile photo Arshad Ansary
      Arshad Ansary

      Hi Ron,

      You are right with my requirement.

      But if UI is showing first 20-30 records only of the 500 records and on click of download the user wants to download the entire list, then it needs to be done in GW/backend.

      From the GW side ,I need to call CL_GUI_FRONTEND class methods to download the data to PC .

      In this case the UI will be passing the URL along with the filter and I will handle the download in the GET_ENTITYSET of the corresponding Entity type after calling the Backend FM . How will I pass the File path,File Type and I need an indicator in GW to understand the user has asked for the Download action?

      Regards

      Arshad

      Author's profile photo Former Member
      Former Member

      Sorry Arshad but what you are proposing is impossible.

      CL_GUI_FRONTEND interacts with SAPGUI API calls. For this to happen, you need a terminal session.

      Gateway communicates via http, is stateless and has no terminal. GW is totally agnostic of the PC or whatever device it is serving.

      You need to use client side development for this, forget Gateway file streaming; you are just complicating the matter!


      If your app wants to send all of the table to file, UI5 must ask for the full table data as an entityset from Gateway and then package it into a download locally.


      However you do it, UI5 has to broker the exchange because GW doesn't know about any PC. šŸ™



      Author's profile photo rajeesh o
      rajeesh o

      Hi Ron

           I have a requirement. i need to store file path in database and store documents in mime repository or any other server and upload and download through odata service.. how can i achieve this

      thanks in advance..

      Author's profile photo Syambabu Allu
      Syambabu Allu

      Hi Raj,

      As i know we can achive using SAP DMS for store file and content from oData Services.

      Thanks,

      Syam

      Author's profile photo rajeesh o
      rajeesh o

      hi Syam ,

      thanks.Do you have any Documents explaning the Concept.My Requirement is to store path in database and store media files in dms.and by clicking the link i should get file from dms.\

      Thanks

      Raj

      Author's profile photo Paul Abrahamson
      Paul Abrahamson

      If your Gateway is running ABAP 7.4 you could perhaps use the ?$format=xlsx URI option if you want to download the data that's bound the a table control in UI5. Just re-execute the same service call that the table is bound to, but append the format=xlsx option and it should trigger the download as a standard browser download.

      Excel Support - SAP Gateway Foundation (SAP_GWFND) - SAP Library

      Author's profile photo Ekansh Saxena
      Ekansh Saxena

      Just to add to your reply. This functionality is available from SP09 on NW740. Re: OData support for Excel

      Regards,

      Ekansh

      Author's profile photo Siva rama Krishna Pabbraju
      Siva rama Krishna Pabbraju

      Hi  Jan,

                     Great Blog....!! I have followed your blog and able to download and upload files from gateway client.

                           I am looking to access this oDATA service from UI5. Can you please share me the code or link which does this work.

      Regards,

      Siva

      Author's profile photo Mike Reader
      Mike Reader

      Siva,

      If you find your service in /IWFND/MAINT_SERVICE, select it and choose Call Browser you can see the entire path to the service.

      -Mike

      Author's profile photo Former Member
      Former Member

      Hi Jan,

      Great Blog!!! Here i am coming up with new requirement like, how can we show more than one attachment in single GET Call.

      Regards

      goudham

      Author's profile photo Former Member
      Former Member

      Hi Experts,

      I have a following problem. Currently we are useing OpenText repository to store attachments. Everything is fine when we are uploading and downloading files in LAN. But when we are outside our network we can't download attachments beacuse URL points to a local IP. Is there a method to download attachments without exposing OpenText repository to Internet?

      Best regards,

      Daniel

      Author's profile photo Pavan Golesar
      Pavan Golesar

      Hi Daniel,

      Did you tried VPN ?

      To my knowledge, It should resolve your issue. šŸ˜‰

      Also let me know if you get this issue resolved by any other mean if not by the one I had mentioned.

      Cheers!!

      --Pavan G

      Author's profile photo Mike Reader
      Mike Reader

      Jan,

      Thanks for posting this, I got this setup fairly quickly and it works really well.

      -Mike

      Author's profile photo kumud ranjan jha
      kumud ranjan jha

      Hi Mike,

      It would be of great help if could help us also to implement this.

      please find my queries mentioned below post.

      Thanks & Regards.

      Kumud Ranjan

      Author's profile photo Johnny MuƱoz
      Johnny MuƱoz

      Hi Jan,

      I could implement all thanks to your blog, thanks again. But still I have the problem of empty keys, What was the solution?

      Best regards,

      Johnny

      Author's profile photo kumud ranjan jha
      kumud ranjan jha

      Hi Johny,

      It would be of great help if could help us also to implement this.

      please find my queries mentioned in below post.

      Thanks & Regards.

      Kumud Ranjan

      Author's profile photo Johnny MuƱoz
      Johnny MuƱoz

      It's done.

      You must complete the fill data entity and end of the code must put the following statement:   

      copy_data_to_ref( EXPORTING is_data = ls_entity                     

                                    CHANGING  cr_data = er_entity ).

      Regards,

      Johnny

      Author's profile photo kumud ranjan jha
      kumud ranjan jha

      Hi Johnny,

      Thanks for your reply... I have written the code as suggested by you, please find the same as attached. please advice for changes needed if any.

      on downloading the PDF file we get error as attached, please have look at it.

      Best Regards.

      Kumud

      code to download.PNG

      Error in downloading PDF file

      PDF download.PNG

      Author's profile photo Johnny MuƱoz
      Johnny MuƱoz

      Hi,

      This error is for other reason. The PDF binary file is corrupted in table, because the response is from the PDF Reader application and not of the NW Gateway.

      Upload correctly the file again. Remember, the correct format en BINARY(LRAW), not XSTRING.

      Regards,

      Johnny

      Author's profile photo kumud ranjan jha
      kumud ranjan jha

      Hi Johnny,

      Thanks for your reply.

      If PDF binary file is corrupted in table then I guess all the files getting uploaded in table is corrupted and as a result of which it is not getting displayed correctly when downloaded.

      Currently uploaded file is referring to the data element XSTRINGVAL in custom table. Please refer the below table. If it referring the wrong type, request you to provide with the correct type.

      Custom Table to upload attachment.PNG

      Thanks & Regards.

      Kumud

      Author's profile photo kumud ranjan jha
      kumud ranjan jha

      Hi Jan,

      Thanks for such a nice documentation on upload and download of attachment using Net-weaver gateways.

      I am trying to implement the same, upload was successful we were able to save the data in table.

      But while download getting some issue.

      On testing the download component using gateway client status code coming is 200 but in response I get statement written as

      "Click "Response in Browser" to display data in the right format."

      upon clicking response browser we get an error saying window photo viewer can not open this picture because either photo viewer doesn't support this file format (please find the error screenshot attached)

      note: we are running on SP04

      Requesting a positive response.

      File Download using gateway client.PNG

      On clicking response browser.PNG

      Best Regards.

      Kumud Ranjan

      Author's profile photo Mike Reader
      Mike Reader

      Kumud,

      I suspect this has nothing to do with the service and more to do with trying to open a png in Windows Photo viewer.  I did a quick Google: Error when trying to view .png files&amp;#58; &amp;#34;windows photo viewer - Microsoft Community

      Try sending a jpg file and see if that works.

      -Mike

      Author's profile photo kumud ranjan jha
      kumud ranjan jha

      Hello Mike,

      Thanks for such a quick reply, we tried with a PDF file it got downloaded but there was no content, it also had error in opening the file.

      If you could please throw some more light on it.

      Thanks & Regards.

      Kumud Ranjan

      Author's profile photo Mike Reader
      Mike Reader

      Did you try a jpg? The reason I suggest that type is the GW Client can render it without opening an external app (like Windows viewer).

      -Mike

      Author's profile photo kumud ranjan jha
      kumud ranjan jha

      Hi Mike,

      Tried with JPEG, on testing with gateway client still not able to view the file, please find the output attached. kindly suggest.

      jpeg file.PNG

      Author's profile photo Mike Reader
      Mike Reader

      Try naming your file entity.jpg.

      Also you may want to try testing with a REST client vs the GW Client, there is a plugin for FireFox that works well.

      -Mike

      Author's profile photo Felipe Andahur
      Felipe Andahur

      Hi guys,

      How I can upload files from aplication web. I using oModel.created('serviceUrl'). I need to pass parameteres into headers. I arrive to GW Client but without parameters.

      Author's profile photo Laxman Chittepu
      Laxman Chittepu

      Hi Thomas,

      Thanks for the nice blog.

      Can you please guide me how can I download the file in SAP UI5 application by calling the service host:port/sap/opu/odata/sap/<servicename>/Files(Pernr='<pernr>',Filename='<filename>')/$value

      Regards,

      Laxman.

      Author's profile photo rajeesh o
      rajeesh o
      Author's profile photo Nitesh Jain
      Nitesh Jain

       

      Hi Jan,

      Thanks for the wonderful blog!! Was able to develop a sample service.

      If we need to send the POST & READ requests in JSON then what should the request be like in this case? Tried the usual ā€œ$format-jsonā€ but that does not work.

      Any ideas? Not sure if this is possible.

      regards
      Nitesh

      Author's profile photo Yan Ma
      Yan Ma

      Hi, Former Member,

      I am Mervin, I’m sorry to trobule you, i have a querstion for need your help.

      I create function model and Neweaver oData.

      i need upload file from SAPUI5. Now, besidesĀ  send ā€œx-s-tokenā€ and ā€œslugā€ to sap Netweaver Gateway , i also send other data to oData from SAPUI5. Example, bellow picture:

      Ā 

      I want send the ZnomberĀ  to oData ,But , it is error, Request URL or element is not defined correctly. Do you know how to send other data to Netweaver.

      Ā 

      regards

      Mervin