cancel
Showing results for 
Search instead for 
Did you mean: 

Fetch .tiff image via URL

bjorn-henrik_zink
Active Participant
0 Kudos

Hi,

I am trying to fetch an image using the CL_HTTP_CLIENT class. My coding looks something like this:


  TRY.
      " Create the HTTP client
      CALL METHOD cl_http_client=>create_by_url
        EXPORTING
          url                = lv_img_url
        IMPORTING
          client             = lo_client
        EXCEPTIONS
          argument_not_found = 1
          plugin_not_active  = 2
          internal_error     = 3.

      IF sy-subrc = 0.
        " Set header fields.
        CALL METHOD lo_client->request->set_header_field
          EXPORTING
            name  = '~request_method'
            value = 'POST'.

        CALL METHOD lo_client->request->set_header_field
          EXPORTING
            name  = '~server_protocol'
            value = 'HTTP/1.1'.

        CALL METHOD lo_client->request->set_header_field
          EXPORTING
            name  = 'Content-Type'
            value = 'image/tiff'.

        "send and receive
        lo_client->send( ).
        lo_client->receive( ).

        "get status
        lo_client->response->get_status( IMPORTING code = lv_return_code ).

        "get the response as binary data
        lv_img_xstring = lo_client->response->get_data( ).

        "close connection
        lo_client->close( ).
      ENDIF. "sy-subrc = 0
    CATCH cx_root.
  ENDTRY.

The code is working fine when the url is pointing to a .jpeg file (and removing the set_header_field part). However, with an .tiff image url it does not work. Any help is greatly appreciated.

I am using the code in an assistance class to get the xstring representation of .tiff images. The xstring is converted using IGS and finally displayed in Web Dynpro ABAP.

Thanks.

Accepted Solutions (0)

Answers (2)

Answers (2)

bjorn-henrik_zink
Active Participant
0 Kudos

Hi again,

this is one of the questions that I would have liked to avoid posting. It turned out that my links where copied from another system and therefore there was no document/image behind the link. Unfortunately, some of the jpeg images were real in the development system and that caused the differing behaviour.

The answer is therefore that the coding posted in this question works fine with .tiff images.

bjorn-henrik_zink
Active Participant
0 Kudos

Hi again,

this is one of the questions that I would have liked to avoid posting. It turned out that my links where copied from another system and therefore there was no document/image behind the link. Unfortunately, some of the jpeg images were real in the development system and that caused the differing behaviour.

The answer is therefore that the coding posted in this question works fine with .tiff images.