cancel
Showing results for 
Search instead for 
Did you mean: 

[WDA]: Add Image dynamically from a Webdynpro SCREEN

Former Member
0 Kudos

Hi Experts,

I have this screen with this default image:

I would like to know, how to Upload (from the desktop) and Display an image when clicking on "ADD PHOTO" button?

Have you code a part of code?

Thank you very much.

Rachid.

Accepted Solutions (1)

Accepted Solutions (1)

Gowtham
Contributor
0 Kudos

Hi Rachid,

Even we too had the same requirement , kindly find the following points and Code.

Create a Node with 3 attributes to capture the Attachment name , Type and content here in the given code node name is 'Attachments' , and create a node with one Xstring attribute to hold the uploaded image in run time here in the given code node name is 'New Image'.


  DATA lo_nd_attachments  TYPE REF TO if_wd_context_node.

  DATA lo_el_attachments  TYPE REF TO if_wd_context_element.

  DATA ls_attachments     TYPE        wd_this->element_attachments.

  DATA lo_nd_new_image    TYPE REF TO if_wd_context_node.

  DATA lo_el_new_image    TYPE REF TO if_wd_context_element.

  DATA ls_new_image       TYPE        wd_this->element_new_image.

  DATA lv_url             TYPE        string.

  DATA lv_guid            TYPE        guid_32.

  DATA lv_cached_response TYPE REF TO if_http_response.

  DATA lv_file            TYPE        xstring.

  lo_nd_new_image = wd_context->get_child_node( name = wd_this->wdctx_new_image ).

  lo_el_new_image = lo_nd_new_image->get_element(  ).

  lo_nd_attachments = wd_context->get_child_node( name = wd_this->wdctx_attachments ).

  lo_el_attachments = lo_nd_attachments->get_element(  ).

  lo_el_attachments->get_static_attributes(

  IMPORTING

  static_attributes = ls_attachments ).

  lv_file = ls_attachments-content.

  IF ls_attachments-type+0(5) EQ 'image'.

    CREATE OBJECT lv_cached_response

      TYPE

        cl_http_response

      EXPORTING

        add_c_msg        = 1.

* set image to mime

    lv_cached_response->set_data( lv_file ).

    lv_cached_response->set_header_field( name = if_http_header_fields=>content_type value = 'IMAGE/PJPEG' ).

    lv_cached_response->set_status( code = 200 reason = 'OK' ).

    lv_cached_response->server_cache_expire_rel( expires_rel = 180 ).

    CALL FUNCTION 'GUID_CREATE'

      IMPORTING

        ev_guid_32 = lv_guid.

    cl_wd_utilities=>construct_wd_url(

        EXPORTING

          application_name = 'ZWDA_TMS'

        IMPORTING

          out_local_url = lv_url ).

    CONCATENATE lv_url '/' lv_guid sy-uzeit INTO lv_url.

    cl_http_server=>server_cache_upload( url = lv_url response = lv_cached_response ).

    MOVE lv_url TO ls_new_image-img.

    lo_nd_new_image->bind_structure( ls_new_image ).

  ELSE.

    wd_this->message(

      message_text = 'Kindly select image type files for upload'

      type = 'E' ).

  ENDIF.

Hope this will solve your issue.

- Gowtham

Answers (0)