cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing BSP File Download using HTTPS URL

Former Member
0 Kudos
419

Hi,

I'm struggling with a problem of downloading a file from a https url. I wrote a BSP App for downloading a file from a unix server.. It works fine when I use a http URL with port 8080 and does not work when I use https.!!

Example:

https://comms.gmsanet.co.za/supplier [ download does not work ]

http://comms.gmsanet.co.za:8080/supplier [ download works ]

When I try to download using https.. it does not pull the file name and path

see code below and suggest me if anything to be chnaged.

In the Form Initialization method:

  • event handler fr data retrieval

DATA: i_file type string,

s_fields TYPE tihttpnvp,

s_fields_line TYPE ihttpnvp,

multipart_form type ref to if_http_entity,

file_upload type xstring,

lv_backend type string,

success type string,

entity type ref to if_http_entity,

file type xstring,

content_type type string,

content_filename type string,

content_length type string,

content_disposition type string,

num_multiparts type i,

i type i value 1,

doEcho type string value 'X',

value type string,

filename type ZFILETAB-fileinfo,

ext1 type string,

ext2 type string,

dsn type string,

bptype like sy-uname,

itab TYPE ZFILETAB,

itab_line TYPE ZFILETABLINE,

file_ext type ZFILETABLINE,

fileinfo type c,

zcount type i.

filename = '/NewMessge.doc'.

content_filename = filename.

  • Check the extension and assign the content type

split filename at '.' into ext1 ext2.

case ext2.

when 'zip'.

content_type = 'application/x-zip-compressed'.

when 'doc'.

content_type = 'application/msword'.

when 'txt'.

content_type = 'text/plain'.

when 'ppt' or 'pps'.

content_type = 'application/vnd.ms-powerpoint'.

when 'xls' or 'exe'.

content_type = 'application/octet-stream'.

when 'gif'.

content_type = 'image/gif'.

when 'jpg' or 'jpeg'.

content_type = 'image/pjpeg'.

when 'htm' or 'html'.

content_type = 'text/html'.

endcase.

dsn = filename.

OPEN DATASET dsn FOR INPUT IN BINARY MODE.

IF sy-subrc NE 0.

zmessage = 'Error opening file'.

navigation->set_parameter( name = 'zmessage' value = zmessage ).

navigation->goto_page( 'downloaderror.htm' ).

exit.

ENDIF.

DO.

READ DATASET dsn INTO <b>file</b>.

EXIT.

ENDDO.

CLOSE DATASET dsn.

  • set response data to be the file content

runtime->server->response->set_data( <b>file</b> ).

runtime->server->response->set_header_field(

name = 'Content-Type'

value = content_type ).

concatenate 'attachment; filename=' filename into content_disposition.

runtime->server->response->set_header_field(

name = 'Content-Disposition'

value = content_disposition ).

  • set the file size in the response

content_length = xstrlen( file ).

runtime->server->response->set_header_field(

name = 'Content-Length'

value = content_length ).

runtime->server->response->delete_header_field(

name = 'Cache-Control' ).

runtime->server->response->delete_header_field(

name = 'Expires' ).

navigation->response_complete( ).

Thanks

Ajay

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member181879
Active Contributor
0 Kudos

Maybe you can first test with BSP application IT00. First test with HTTP and then with HTTPS. Run default.htm page. Then on the left select point 3.2 "...including file up-/download". For your first tests use a .JPG image, and in all cases set the echo checkbox. It should work for both HTTP and HTTPS.

The reason for this in that in HTTPS mode, the object is not cached, but passed directly from the browser to the "viewer" application. And this is specifically the problem you have now. In HTTPS mode, the file is not on disk, and browser has no way to start the "viewer" for you filetype without writing the browser to cache.

All of this is tied to configuration setting. In your browser settings, look at tools, advanced options. There is a checkbox "Do not save encrypted pages to disk".

Former Member
0 Kudos

Hi Brian,

I have the same problem as Ajay Yeluguri. In http mode I can generate a download of an Excel document but when we use the portal in https it doesn't work.

When I try to download using https it does not pull the file name and path and when I choose download I have a error message : "Internet Explorer cannot download from ..."

I've test the point 3.2 "... including file up/download" of the BSP application IT00 and it works fine in http and https mode. My problem is not the upload but the download. And in this application the uploaded document is opened in the Internet Explorer window but I want to generate a Save as... window to download the file.

Have you an idea what i can do to solve my problem.

Thanks

Yann

former_member181879
Active Contributor
0 Kudos

Look at adding the Content-Disposition header to specify the file should be saved immediately. See also: <a href="/people/mark.finnern/blog/2003/09/23/bsp-programming-handling-of-non-html-documents">BSP Programming: Handling Of Non-HTML Documents</a>

Former Member
0 Kudos

Hi Brian,

I know how to do the download on client side with adding the Content-Disposition header and the Content-Type header. This is not my problem because I have do it and it works fine. But it works only in HTTP mode and not in HTTPS. So I search a solution in HTTPS mode. I think that it is impossible to do a file transfer in HTTPS because it works only for content-type like text/html which can be put in Internet Explorer Window.

Do you know solutions to make a download in HTTPS ?

Thanks.

Yann

former_member181879
Active Contributor
0 Kudos

Yes, look in my referenced document to also remove the caching headers. This is usually the problem.

Former Member
0 Kudos

Brian,

I have found the solution. It was a problem with removing the caching headers (pragma). Now it works with HTTPS protocol. Thanks a lot for your help.

Regards.

Yann