cancel
Showing results for 
Search instead for 
Did you mean: 

Download image to my pc

Former Member
0 Kudos

Hello Friends,  I have a rerequirement to download the image to the pc(when user click a button),  I can upload to image to the table and show the image in a pop-up to users but i want the image to be downloadable at the same time,  How i show the image to the user is like below coding.

Thanks

method WDDOINIT .

*

*

   DATA :   lo_cache            TYPE REF TO if_http_response,

            lv_guid             TYPE        guid_32,

            lv_host             TYPE        string,

            lv_port             TYPE        string,

            lv_protocol         TYPE        string,

            lv_url              TYPE        string.

   CREATE OBJECT lo_cache

     TYPE

     cl_http_response

     EXPORTING

       add_c_msg = 1.

   SELECT * FROM my_table

          INTO TABLE it_image where file_no eq lv_file_no.

   lo_nd_image = wd_context->get_child_node( name = wd_this->wdctx_image ).

* Generating the URL for the image.

   LOOP AT it_image INTO wa_image.

     ls_image-file_no = wa_image-file_no.

     ls_image-file_name = wa_image-file_name.

* Setting the XString format of image content in the cache.

     lo_cache->set_data( wa_image-content ).

     lo_cache->set_header_field( name  = if_http_header_fields=>content_type

                                       value = 'image/jpeg' ).

* Create a unique URL for the object

   CALL FUNCTION 'GUID_CREATE'

     IMPORTING

       ev_guid_32 = lv_guid.

* Set the Response Status

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

* Set the timeout for the cache

       lo_cache->server_cache_expire_rel( expires_rel = 360 ).

* Getting the host , port and Protocol of the server

       CALL METHOD cl_http_server=>get_location

          EXPORTING

            server       = cl_wdr_task=>server

          IMPORTING

            host         = lv_host

            port         = lv_port

            out_protocol = lv_protocol.

* Generating the URL

       CONCATENATE

          lv_protocol '://' lv_host ':' lv_port '/sap/bc/webdynpro/sap/'

          lv_guid '.JPG'

          INTO lv_url.

* Upload the generated URL in the cache

         cl_http_server=>server_cache_upload( url      = lv_url

                                             response = lo_cache ).

     ls_image-image = lv_url.

     APPEND ls_image TO lt_image.

     CLEAR : wa_image, ls_image.

   ENDLOOP.

   lo_nd_image->bind_table( new_items = lt_image set_initial_elements = abap_true ).

endmethod.

Accepted Solutions (1)

Accepted Solutions (1)

former_member184578
Active Contributor
0 Kudos

Hi,

You can use class cl_wd_runtime_services method attach_file_to_response.

In the onAction of button get the image data and pass to the method:

  cl_wd_runtime_services=>attach_file_to_response(

      i_filename  =    <file_name>

      i_content   =    <file_data>

      i_mime_type = '<MIME>' )

Or you can simple use Filedownload UI. For reference check this wiki: http://wiki.sdn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP

Hope this helps u.,

Regards,

Kiran

Answers (0)