cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

PDF download froM HTTPS URL

MariusStoica
Active Participant
0 Likes
10,512

Hi guys,

I'm trying to download a PDF created by a third party from an API. I'm in a EHP4 FOR SAP ERP 6.0 / NW7.01 environment.

I created using SM50 a HTTP destination (type G and default SSL client) that I use to do POST and GET requests, and everything goes well, unless I try to download a PDF file.

Using:

* Create HTTP client object
    CALL METHOD cl_http_client=>create_by_destination
      EXPORTING
        destination           = 'HTTPS'
      IMPORTING
        client                = lcl_client
      EXCEPTIONS
        destination_not_found = 1
        internal_error        = 2.

I get a correct response:

IF lv_status = 200.
 lv_response = lcl_client->response->get_cdata( ).
ENDIF.

And although "lv_response" has the data that looks correct:

Field    LV_RESPONSE
Data Type          CString{26202}
Absolute Type      \TYPE=STRING

View
      %PDF-1.4##%����##7 0 obj##<</Type /XObject /Subtype /Image /Width 152 /Height 

When I try to transfer the string to the "file" something goes wrong. Here is the code I use to write the file:

DATA: ls_string             TYPE lvc_s_1022,
      lt_string             TYPE lvc_t_1022.

        DO .
          lv_len = STRLEN( lv_response ).
          IF lv_len <> 1022.
            ls_string-line = lv_response+0(lv_len).
          ELSE.
            ls_string-line = lv_response+0(1022).
          ENDIF.
          APPEND ls_string TO lt_string.
          SHIFT lv_response BY 1022 PLACES.
          IF lv_response IS INITIAL.
            EXIT.
          ENDIF.
        ENDDO.

        CONCATENATE lv_file '\' lv_filename '.pdf' INTO lv_file.

        CALL FUNCTION 'SCMS_DOWNLOAD'
          EXPORTING
            filename = lv_file
            binary   = 'X'
            frontend = 'X'
            mimetype = 'charset=UTF8'
          TABLES
            data     = lt_string
          EXCEPTIONS
            error    = 1
            OTHERS   = 2.

        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.

I tried playing with the MIMETYPE parameter and BINARY paratemer, with no success. When opening the file with Acrobat Reader I get the error that the file is corrupt.

Any idea why this doesn't work ?

Kind regards,

Marius

View Entire Topic
RaymondGiuseppi
Active Contributor

You didn't fill the FILESIZE parameter?

MariusStoica
Active Participant
0 Likes

Hi Giuseppi,

No. I didn't. How would I calculate that ?
Marius.

RaymondGiuseppi
Active Contributor
0 Likes

Try first value of STRLEN( lv_response )

MariusStoica
Active Participant
0 Likes

Hi,

That didn't work. Same error.

I never tried using FM "SCMS_HTTP_GET_FILE" instead of the class. Do you think it might work ?

Or should I use another function to "download" the file ?

Regards,
Marius