Skip to Content
0
Former Member
Feb 23, 2005 at 10:13 AM

Accessing BSP File Download using HTTPS URL

246 Views

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