Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Convert Binary xstring value to image

Former Member
0 Likes
7,235

Hi,

DATA : url TYPE string.

  url = 'http://img87.imageshack.us/img87/5673/rotatetrans.png'.
data: content type xstring.

DATA : http_client TYPE REF TO IF_HTTP_CLIENT.

  CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL
    EXPORTING
      URL                = url
    IMPORTING
      CLIENT             = http_client
    EXCEPTIONS
      ARGUMENT_NOT_FOUND = 1
      PLUGIN_NOT_ACTIVE  = 2
      INTERNAL_ERROR     = 3
      others             = 4.


  IF SY-SUBRC = 0.
    http_client->send( ).
    http_client->receive( ).
    content = http_client->response->get_data( ).
    http_client->close( ).

     "Convert the "content" value to image.


  BREAK-POINT.

  ENDIF.

How to convert the "content" varaible value to image a store it in the local machine.

Regards,

Alenlee MJ

3 REPLIES 3
Read only

SujeetMishra
Active Contributor
0 Likes
3,506

Hi Alenlee,

Use FM SSFC_BASE64_ENCODE.

also refer similar issue posted in below thread.

http://scn.sap.com/message/14340824

Regards,

Sujeet

Read only

Former Member
3,506

Hi All,

Finally I got the answer check it out,

DATA : url TYPE string.

url ='http://img87.imageshack.us/img87/5673/rotatetrans.png'.
data: content type xstring.
DATA : http_client TYPE REF TO IF_HTTP_CLIENT.

TYPES : BEGIN OF TY_BINARY,
          BINARY_FIELD(1000) TYPE C,
        END OF TY_BINARY.

*DATA : LV_XSTRING type XSTRING.
DATA : HEX_TAB1 TYPE TABLE OF TY_BINARY WITH HEADER LINE.


  CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL
    EXPORTING
      URL                = url
    IMPORTING
      CLIENT             = http_client
    EXCEPTIONS
      ARGUMENT_NOT_FOUND = 1
      PLUGIN_NOT_ACTIVE  = 2
      INTERNAL_ERROR     = 3
      others             = 4.


  IF SY-SUBRC = 0.
    http_client->send( ).
    http_client->receive( ).
    content = http_client->response->get_data( ).
    http_client->close( ).


    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    BUFFER        = content
*  IMPORTING
*    OUTPUT_LENGTH = BYTES
  TABLES
    BINARY_TAB    = HEX_TAB1.   "here you have results you need.


    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
*       BIN_FILESIZE                    =
        FILENAME                        = 'C:\PHOTOS\TEST2.BMP'
        FILETYPE                        = 'BIN'
*       APPEND                          = ' '
*       WRITE_FIELD_SEPARATOR           = ' '
*       HEADER                          = '00'
*       TRUNC_TRAILING_BLANKS           = ' '
*       WRITE_LF                        = 'X'
*       COL_SELECT                      = ' '
*       COL_SELECT_MASK                 = ' '
*       DAT_MODE                        = ' '
*       CONFIRM_OVERWRITE               = ' '
*       NO_AUTH_CHECK                   = ' '
*       CODEPAGE                        = ' '
*       IGNORE_CERR                     = ABAP_TRUE
*       REPLACEMENT                     = '#'
*       WRITE_BOM                       = ' '
*       TRUNC_TRAILING_BLANKS_EOL       = 'X'
*       WK1_N_FORMAT                    = ' '
*       WK1_N_SIZE                      = ' '
*       WK1_T_FORMAT                    = ' '
*       WK1_T_SIZE                      = ' '
*       WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
*       SHOW_TRANSFER_STATUS            = ABAP_TRUE
*       VIRUS_SCAN_PROFILE              = '/SCET/GUI_DOWNLOAD'
*     IMPORTING
*       FILELENGTH                      =
      TABLES
        DATA_TAB                        HEX_TAB1
*       FIELDNAMES                    =
     EXCEPTIONS
       FILE_WRITE_ERROR                = 1
       NO_BATCH                        = 2
       GUI_REFUSE_FILETRANSFER         = 3
       INVALID_TYPE                    = 4
       NO_AUTHORITY                    = 5
       UNKNOWN_ERROR                   = 6
       HEADER_NOT_ALLOWED              = 7
       SEPARATOR_NOT_ALLOWED           = 8
       FILESIZE_NOT_ALLOWED            = 9
       HEADER_TOO_LONG                 = 10

       DP_ERROR_CREATE                 = 11
       DP_ERROR_SEND                   = 12
       DP_ERROR_WRITE                  = 13
       UNKNOWN_DP_ERROR                = 14
       ACCESS_DENIED                   = 15
       DP_OUT_OF_MEMORY                = 16
       DISK_FULL                       = 17
       DP_TIMEOUT                      = 18
       FILE_NOT_FOUND                  = 19
       DATAPROVIDER_EXCEPTION          = 20
       CONTROL_FLUSH_ERROR             = 21
       OTHERS                          = 22

              .

    IF SY-SUBRC <> 0.
* Implement suitable error handling here
    ENDIF.

  BREAK-POINT.

  ENDIF.

Read only

0 Likes
2,399

Thank you Alenlee!

This really helped me in one of my projects. 🙂

Warm Regards,

Danish Makhdum.