This document is about how to enhancement our OData service  – Download File.


Currently base on training material, we usually redefine GET_STREAM method and pass mime type and stream value to the result.

ls_streammime_type = outputreturnMIME_TYPE .
ls_stream
-value = outputreturnDOCUMENT_STREAM .
copy_data_to_ref
( EXPORTING is_data = ls_stream
CHANGING  cr_data = er_stream ).

This works, however the problem is if you trigger the service in Chrome. You can only get a document with named ‘entity’.

/wp-content/uploads/2016/01/1_872984.png

Problem

  • What if customer has already stored file name in ECM or in Database? They want to see the real name.
  • What if customer don’t want to direct download, they may want to review the file before download.

Solution

Solution to this is to set a header to http framework. I attached code below.

DATA ls_lheader TYPE ihttpnvp.
“DATA lv_filename TYPE string.
“lv_filename = escape( val = lv_filename format = cl_abap_format=>e_url ).
ls_lheader
name = ‘Content-Disposition’.
ls_lheader
value = ‘outline; filename=”Mobile.pdf”;’.
set_header
( is_header = ls_lheader ).

ls_streammime_type = outputreturnMIME_TYPE .
ls_stream
value = outputreturnDOCUMENT_STREAM .
copy_data_to_ref
( EXPORTING is_data = ls_stream
CHANGING  cr_data = er_stream ).

Let’s test the result now:

2.PNG

If customer want to preview the document instead of directly download, please change code as below.

ls_lheadervalue = ‘inline; filename=”Mobile.pdf”;’.

Let’s test the result:

A new page was opened for preview, you can right click and choose to save. File name ‘Mobile.pdf’ comes up.

3.PNG

To report this post you need to login first.

4 Comments

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

  1. Burak Oral

    Thanks for document.

    It does not work in ie 10 browser.

    Does anyone have any suggestions?

    I use below code in sapui5.

    window.open(“/sap/opu/odata/sap/MYSERVICE_SRV/DownloadFileSet(‘”+ guid +”‘)/$value”);

    (0) 
  2. Grace Djomo

    Good afternoon  Eric Zhao,

    I just want to say THANK YOU for this SOLUTION which I used right now. Through this I was also able to learn new things. THANKS and have a GREAT DAY 🙂 🙂 🙂

    (0) 

Leave a Reply