Skip to Content

File Attachment using gateway

Hi Everyone,

New scenario: uploading and downloading file using SAP Netweaver Gateway .

Dont know how to solve this one .

I like to have ur valuable suggestion and Advice for this requirement.

Thanks in Advance,

Regards,

Jibin JOy

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    Posted on Nov 08, 2012 at 05:55 AM

    Hi Jibin / Jessie

    TLDR The answer depends on the requirement. There are a few ways I can think of to achieve Uploading and Downloading files with Gateway services. The most efficient way is to provide URL links to the file content, then have separate client calls stream the data to and from the server via the Gateway service or maintain the data by methods independent of the Gateway service .

    The OData protocol enables you to define data feeds that also make binary large object (BLOB) data, such as photos, videos, and documents available to client applications that consume the OData feeds. For performance reasons it is not good practice to return the BLOB's in the feed themselves, rather call the Binary Data, known as a Media Resource separately via a Media Link Entry present in the feed.

    eg.

    <content type="image/jpeg" src="EmployeePhoto(4)/$value" />

    <link rel="edit-media" title="EmployeePhoto" href="EmployeePhoto(4)/$value" />

    or

    <content type="image/jpeg" src="http://www.linkedin.com/profilephotos/xyz.jpg" />

    Example of using Media Links to retrieve Workflow attachments. Workflow Services -> Media Links - see

    DPC: /IWWRK/CL_MGW_RT_WORKFLOW

    MPC: /IWWRK/CL_MGW_MED_WORKFLOW

    If you have access to the the Electronic Medical Record Gateway services you can see both how to use both Media Links and Binary fields in the feed

    /MEMR/CL_ET_ATTACHMENT_HANDLER

    /MEMR/CL_ET_DOCUMENT_HANDLER

    To support streaming in Gateway services,the DPC has the following methods :

    /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM

    /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM

    /IWBEP/IF_MGW_APPL_SRV_RUNTIME~UPDATE_ENTITY

    /IWBEP/IF_MGW_APPL_SRV_RUNTIME~DELETE_STREAM

    The first half of this document explains how it should work OData support for streams

    The only full CRUD example i could find is

    /IWBEP/CL_MGW_RT_SFLIGHT local class LCL_CARRIER->Create/Update/Delete_Stream, however this code doesn't seem active or recent.

    Hope it helps.

    Cheers

    John P

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hello Vinit,

      We did not have a SAPUI5 app. Our app UI was built on iOS platform using X-Code. The image data was converted into BASE64 and then passed as raw data in http request. On SAP side, I did following:

      1. use FM SCMS_XSTRING_TO_BINARY to convert the XSTRING to Binary

      2. use FM SCMS_BINARY_TO_STRING to convert the binary into a string

      3. use FM SSFC_BASE64_DECODE to decode the String in BASE64

      4. Save the data as-is as a file with .png extension on application server.

      I hope this helps.

      Thanks,

      Rutul

  • Posted on May 11, 2016 at 10:56 AM

    Please find code to get the file content if file is uploaded by Form

    FUNCTION ZFM_GW_STREAM_READER.
    *"----------------------------------------------------------------------
    *"*"Local Interface:
    *" IMPORTING
    *" VALUE(IV_FILE_CONTENT) TYPE XSTRING
    *" VALUE(IV_CONTENT_TYPE) TYPE STRING OPTIONAL
    *" EXPORTING
    *" VALUE(EV_FILE_CONTENT) TYPE XSTRING
    *" VALUE(ET_REQUEST_HEADER) TYPE TIHTTPNVP
    *" EXCEPTIONS
    *" INVALID_FILE_CONTENT
    *"----------------------------------------------------------------------
    CONSTANTS : lc_boundary TYPE string VALUE 'boundary=',
    lc_new_line TYPE string VALUE '0D0A',
    lc_srt_file TYPE string VALUE '0D0A0D0A',
    lc_key_val_sep TYPE string VALUE ':'.
    DATA:
    lv_xlen TYPE int4,
    lv_bolen TYPE int4,
    lv_bvalue TYPE string,
    lv_cufile_content TYPE string,
    lv_bxs TYPE string,
    lv_header TYPE string,
    lv_content_footer TYPE string,
    lv_content TYPE string,
    lv_footer TYPE string,
    lv_end_file1 TYPE string,
    lv_end_file2 TYPE string,
    lv_bxvalue TYPE xstring,
    lt_fnd_boundary TYPE match_result_tab,
    lt_fnd_temp TYPE match_result_tab,
    ls_fnd_boundary TYPE match_result,
    ls_headers TYPE ihttpnvp,
    lv_xsheaders TYPE xstring,
    lv_sheaders TYPE string,
    ls_xsheaders TYPE string,
    lt_xsheaders TYPE TABLE OF string.

    DATA : lv_contant_final_val TYPE string,
    lv_contant_temp_val TYPE string,
    lv_content_type TYPE string,
    lv_content_type_xstr TYPE xstring.

    lv_cufile_content = iv_file_content.
    lv_content_type = iv_content_type.

    " In SP5 Server the content type might be empty. So,This if condition is used to fetch
    " the file name/content type from xstring content
    IF lv_content_type IS INITIAL.
    " To split the xstring where new line occurs.
    SPLIT lv_cufile_content AT lc_new_line INTO lv_contant_final_val lv_contant_temp_val .
    " Remove two dash from the the xstring content
    SHIFT lv_contant_final_val BY 4 PLACES LEFT.
    lv_content_type_xstr = lv_contant_final_val.
    CLEAR lv_contant_final_val.
    " Convert Xstring to string
    CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
    EXPORTING
    im_xstring = lv_content_type_xstr
    IM_ENCODING = 'UTF-8'
    IMPORTING
    EX_STRING = lv_contant_final_val .

    " Add prefix data to the string value.
    IF sy-subrc = 0.
    CONCATENATE 'multipart/form-data; boundary=' lv_contant_final_val INTO lv_content_type.
    ENDIF.

    ENDIF.

    "Finding the Boundary value from content type
    FIND FIRST OCCURRENCE OF lc_boundary IN
    lv_content_type
    RESULTS lt_fnd_boundary.
    CHECK sy-subrc EQ 0 .
    READ TABLE lt_fnd_boundary INTO ls_fnd_boundary INDEX 1 .
    lv_bolen = ls_fnd_boundary-offset + ls_fnd_boundary-length.
    "Creating body boundary value for body with extra -- ( --<Boundary value> )
    CONCATENATE '--' lv_content_type+lv_bolen INTO lv_bvalue.
    CALL FUNCTION 'ECATT_CONV_STRING_TO_XSTRING'
    EXPORTING
    im_string = lv_bvalue
    IMPORTING
    ex_xstring = lv_bxvalue.
    lv_bxs = lv_bxvalue.
    lv_xlen = strlen( lv_bxs ).
    "Verify whether Boundary key in Request Body with new line (ODOA)
    IF lv_cufile_content+0(lv_xlen) EQ lv_bxvalue AND lv_cufile_content+lv_xlen(4) EQ lc_new_line.
    "Split the Header from body request from the body boundary key
    SPLIT lv_cufile_content AT lc_srt_file INTO lv_header lv_content_footer.
    "Split the footer from body request from the body boundary key
    "footer start with two format
    "one is just <body boundary value> with new line (ODOA)
    "and another is <body boundary value>--
    CONCATENATE lc_new_line lv_bxs lc_new_line INTO lv_end_file1.
    FIND FIRST OCCURRENCE OF lv_end_file1 IN
    lv_content_footer .
    IF sy-subrc EQ 0 .
    SPLIT lv_content_footer AT lv_end_file1 INTO lv_content lv_footer.
    ELSE.
    CONCATENATE lc_new_line lv_bxs '2D2D' INTO lv_end_file2.
    CLEAR lt_fnd_temp.
    FIND FIRST OCCURRENCE OF lv_end_file2 IN
    lv_content_footer.
    IF sy-subrc EQ 0 .
    SPLIT lv_content_footer AT lv_end_file2 INTO lv_content lv_footer.
    ELSE.
    RAISE invalid_file_content. "No Ending body boundary key
    ENDIF.
    ENDIF.
    ev_file_content = lv_content.
    ELSE.
    RAISE invalid_file_content. "No starting body boundary key
    ENDIF.
    "Fetch the request information from the Request
    SPLIT lv_header AT lc_new_line INTO TABLE lt_xsheaders.
    LOOP AT lt_xsheaders INTO ls_xsheaders FROM 2.
    lv_xsheaders = ls_xsheaders.
    CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
    EXPORTING
    im_xstring = lv_xsheaders
    IMPORTING
    ex_string = lv_sheaders.
    SPLIT lv_sheaders AT lc_key_val_sep INTO ls_headers-name ls_headers-value .
    IF sy-subrc EQ 0.
    CONDENSE : ls_headers-name , ls_headers-value.
    APPEND ls_headers TO et_request_header.
    ENDIF.
    ENDLOOP.
    ENDFUNCTION.


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 10, 2019 at 12:04 PM

    i resolved webkitformboundary problem putting a Ajax requisition and send the file object of ui5 in the event handleUploadComplete

     
                    handleUploadComplete: function (oEvent) {
     
                        var oCremer = this.byId(oEvent.getParameter("id"));
    
                        $.ajax({
                            url: '-hide url-/GW_UPLOADER_SRV/uploadSet',
                            type: 'POST',
                            data: oCremer.FUEl.files[0],
                            contentType: false,
                            processData: false,
                            success: function (response) {
                            },
                            error: function (response, x) {
                            }
                        });
    
    
                    },
    
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 08, 2012 at 12:57 AM

    I have the same question and I am looking forward someone could give some hints on this.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 30, 2013 at 11:49 AM

    Dear Friends,

    I am facing a scenario wherein for a header(1st Entity) I need to upload multiple attachments(2nd Entity).

    I have established an association and navigation between 2 entities. I understand that GET_STREAM/CREATE_STREAM are called based on operation via HTTP.

    My issues is, how can I call the CREATE_STREAM or GET_STREAM multiple times for an entity ?.

    Regards,

    Venkat

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 07, 2014 at 02:30 PM

    Hi Jibin,

    Did you find a solution to your problem? I am facing the exact issue with the file surrounded by webkitformboundary when it is sent to the CREATE_STREAM method. The browser is IE8, so not much can be done here.

    Regards

    Neha

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.