cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly implement the method CREATE_STREAM for File Upload in the SAP Gateway Server

Former Member
0 Kudos
34,209

Good morning everyone,

It is me again with another issue where I NEED the help of all the GREAT EXPERTS here. For a couple of days now, I have been trying to  familiarize myself with File Upload and Download as Service from the SAP Gateway OData. I read a couple of BLOGS here and from there I was able to gather some knowledges. Thank you SO MUCH to those AUTHORS, without their inputs, I would have been completely LOST. This particular blog was HELPFUL =>

There the author used the UPDATE_STREAM method to UPLOAD the file to the SAP Back-end system. I used his approach and it worked fine. Now I was curious and wanted to know if I could try to implement the CREATE_STREAM method, which is actually the one to use to CREATE(UPLOAD) a new file. Before that I created a transparent table named 'ZZUPLD' to store the uploaded files. Here is a screenshot of that table which has a total of 6 fields, where the most important are the FILENAME, MIMETYPE and VALUE

Now after creating the project in SEGW and inside it the Entity named File which was marked as MEDIA resource and has only ONE property in my case(the filename), I redefined the CREATE_STREAM method of the CLASS DPC_EXT according to all the blogs' documentations.

Below is my OWN implementation of the CREATE_STREAM

***************************************************************Code Begin*****************************************************************************************

method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM.
**try.
*CALL METHOD SUPER->/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM
*  EXPORTING
**    iv_entity_name          =
**    iv_entity_set_name      =
**    iv_source_name          =
*    IS_MEDIA_RESOURCE       =
**    it_key_tab              =
**    it_navigation_path      =
*    IV_SLUG                 =
**    io_tech_request_context =
**  importing
**    er_entity               =
*    .
** catch /iwbep/cx_mgw_busi_exception .
** catch /iwbep/cx_mgw_tech_exception .
**endtry.

" This method actually performs the File UPLOAD process. The file which is inserted in the HTTP POST request
" has to be saved in the transparent table, predefined for it. The table name is 'ZZUPLD' and it consists of
" 6 fields: MANDT, FILENAME, SYDATE, SYTIME, VALUE, MIMETYPE. Except from the MANDT field which is filled
"AUTOMATICALLY the others 5 fields MUST be filled here accordingly

  data: ls_file type ZZUPLD
        .

"Now fill the ls_file accordingly

  ls_file-filename = iv_slug.
  ls_file-sydate   = sy-datum.
  ls_file-sytime   = sy-uzeit.
  ls_file-mimetype = is_media_resource-mime_type.
  ls_file-value    = is_media_resource-value.

  "Fill the export parameter er_entity accordingly
  copy_data_to_ref(
    exporting
      is_data = ls_file
    changing
      cr_data = er_entity )
      .



  "Now add the file to the transparent table

  MODIFY zzupld from ls_file.



   endmethod.


***************************************************************Code End*****************************************************************************************


Here is the screenshot of the UPLOAD process using SAP Gateway Client tool




Here is a screenshot of HTTP Response with an ERROR message EVEN THOUGH the FILE is actually UPLOADED  and STORED in the ZZUPLD table .




Here is the screenshot where I used the GET_STREAM method to DOWNLOAD the previous UPLOADED file and as you can see the FILE was really UPLOADED to the Back-end



Can someone PLEASE tell me why the HTTP Response of the UPLOAD REQUEST(CREATE_STREAM) has an ERROR even though the file is SUCCESSFULLY uploaded? I think it is related to my implementation of CREATE_STREAM. Thanks in ADVANCE for you SUPPORT and have a GREAT day

View Entire Topic
abdulkalam_a
Participant
0 Kudos

Thank you so much all for the very useful blog..!!