cancel
Showing results for 
Search instead for 
Did you mean: 

Download file from SAPUI5 application.

Former Member
0 Kudos

Hi all,

my purpose is to dowload a file from a SAPUI5 application.

I found some discussion about this topic, but always using the sap gateway, but in my case this is not possible because I do not have the gateway.

In my scenario the user click on a file name in a list and through an ajax call I extract the file content in xstring format.

this is the code in the controller of my view

var oParameters = {
   title: oObject.phio_fname,   //filename
   type:  oObject.phio_ext,     //file type
   id: selectedDetail.id           //purchase order number

    };

    //Ajax to back-end

    $.ajax({

   url : "/zui5/index.html?application=POA&area=DOWNLOAD_ATTACH",
   contentType : "application/json",
   dataType : 'json',
   data : oParameters
     });    //Ajax call completed

in my http handler

  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

    EXPORTING

      input_length       = lv_bin_size

    IMPORTING

      BUFFER             = lv_xstring

    tables

      binary_tab         = lt_phio_content

*   EXCEPTIONS

*     FAILED             = 1

*     OTHERS             = 2        .

  ls_file-file_name     = lv_title.

  ls_file-file_type     = lv_type.

  ls_file-file_content  = lv_xstring.

server->response->set_data( data = ls_file-file_content ).
server->response->set_content_type( content_type = ls_file-file_type ).

Everything work correctly until the server response, but I am not getting any result in my page.

Is it possible to achieve this result without the gateway?

If not what I am missing?

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

you dont need ajax..

Download File Using Javascript/jQuery - Stack Overflow

var $idown;  // Keep it outside of the function, so it's initialized once.
downloadURL
: function(url) {
 
if ($idown) {
  $idown
.attr('src',url);
 
} else {
  $idown
= $('<iframe>', { id:'idown', src:url }).hide().appendTo('body');
 
}
},
//... How to use it:
downloadURL
('/zui5/index.html?application=POA&area=DOWNLOAD_ATTACH' + jQuery.param( oParameters ) );

Answers (1)

Answers (1)

CCSCS
Explorer
0 Kudos

Hi everybody,

you can use sap.m.URLHelper in SAPUI5, which has some positive effects. Here is a blog-article, that discusses the disadvantage of other methods like using an iframe:

Six and three half ways to start a file download in SAPUI5 (and maybe a few more)