cancel
Showing results for 
Search instead for 
Did you mean: 

How to upload images in custom table?

former_member210804
Active Participant
0 Kudos

Hi friends,

i have a requirement to upload images in my custom table.

I imported 3 images in my WDA through MIME. I have 3 buttons.

On-click of button ,corresponding image should upload in my custom table.

I have done it using FileUpload UI element.But not able to upload the MIME images which we imported.

Pls give me the steps to follow.

Thanks & regards,

Narasimha Rao Putturi.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos
former_member210804
Active Participant
0 Kudos

Hi Amol,

Thank you for the reply..

Could you please send me information on Webdynpro ABAP.

Best regards,

Narasimha.

former_member210804
Active Participant
0 Kudos

Hi friends,

Kindly provide me the solution for my requirement.

Best regards,

Narasimha    

former_member210804
Active Participant
0 Kudos

Hi friends,

I got solved my issue myself..I m mentioning the following steps.

1. to read the mime repository objects.

   DATA mr TYPE REF TO if_mr_api.
   DATA lurl TYPE string.
   DATA: e_xstring TYPE xstring.

   mr = cl_mime_repository_api=>get_api( ).

2. To get the URL.


CALL METHOD cl_wd_utilities=>construct_wd_url(
     EXPORTING
       application_name = 'Component Name'
     IMPORTING
       out_local_url    = lurl ).

3. Concatenate mime image to url

CONCATENATE lurl '/' 'EMPTY.JPG' INTO lurl.

4. Get the xstring value of mime image

   mr->get( EXPORTING i_url = lurl
            IMPORTING e_content = e_xstring ).

5. Uploading the image to custom table

     CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH'
       EXPORTING
         full_name     =  mime repository object name
       IMPORTING
         stripped_name = lv_file_name
*       FILE_PATH     = FILE_PATH
       EXCEPTIONS
         x_error       = 1
         OTHERS        = 2.
     IF sy-subrc <> 0.
       lv_msg_text = 'System error: while reading file location'.
       lv_msg_type = 3.
     ELSE.
       SHIFT lv_file_name LEFT DELETING LEADING '0'.
       lv_lfname = lv_file_name.
       CALL FUNCTION 'SPLIT_FILENAME'
         EXPORTING
           long_filename  = lv_lfname
         IMPORTING
*         PURE_FILENAME  = PURE_FILENAME
           pure_extension = lv_ext.
       TRANSLATE lv_ext TO LOWER CASE.

       IF lv_ext = 'png' OR lv_ext = 'gif' OR lv_ext = 'jpeg' OR lv_ext = 'jpg' OR lv_ext = 'bmp'.

         CREATE OBJECT cached_response
           TYPE
           cl_http_response
           EXPORTING
             add_c_msg = 1.


         lv_file_content = e_xstring.


         cached_response->set_data( lv_file_content ).
         cached_response->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
         cached_response->set_status( code = 200 reason = 'OK' ).

***Set the Cache Timeout - 60 seconds - we only need this in the cache
***long enough to build the page and allow the IFrame on the Client to request it.
         cached_response->server_cache_expire_rel( expires_rel = 360 ).

         CALL METHOD cl_http_server=>get_location
           EXPORTING
             server       = cl_wdr_task=>server
           IMPORTING
             host         = lv_host
             port         = lv_port
             out_protocol = lv_protocol.

         CONCATENATE
           lv_protocol '://' lv_host ':' lv_port '/sap/bc/webdynpro/sap/'
           lv_guid '.JPG'
           INTO lv_url.

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

*         set single attribute
         lo_el_image->set_attribute(
           name `LINK`
           value = lv_url ).

         ls_img-id         = wd_this->gv_last_id.
         ls_img-img = e_xstring.
         MODIFY zrao_img FROM ls_img.     "Modifying the custom table with the image.

Best Regards,

Narasimha.

Answers (2)

Answers (2)

bhushan_ghule
Active Participant
0 Kudos
Former Member
0 Kudos

Hi,

You can store the contents of an image in a custom table in a Xstring format. Once you store the contents of image as XSTRING, you can bring back the image from xstring.

Also if you store the images in MIME already and if you are going to use only the uploaded images via MIME, better get images from mime instead of storing in custom table. You can store the image id in your custom table, while retrieving use MIME object.

~Thanks

Rupachandran

former_member210804
Active Participant
0 Kudos

Hi Rupachandran,

I wrote the following code..

*   navigate from <CONTEXT> to <IMAGE> via lead selection
   lo_nd_image = wd_context->get_child_node( name = wd_this->wdctx_img ).
*   get element via lead selection
   lo_el_image = lo_nd_image->get_element( ).

                                                               " empty.jpg comes from the MIME objects,  
   ls_image-name = 'empty.jpg'.                  " File needs to be uploaded in ZRAO_IMG table

     CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH'
       EXPORTING
         full_name     = ls_image-name
       IMPORTING
         stripped_name = lv_file_name
*       FILE_PATH     = FILE_PATH
       EXCEPTIONS
         x_error       = 1
         OTHERS        = 2.
     IF sy-subrc <> 0.
       lv_msg_text = 'System error: while reading file location'.
       lv_msg_type = 3.
     ELSE.
       SHIFT lv_file_name LEFT DELETING LEADING '0'.
       lv_lfname = lv_file_name.
       CALL FUNCTION 'SPLIT_FILENAME'
         EXPORTING
           long_filename  = lv_lfname
         IMPORTING
*         PURE_FILENAME  = PURE_FILENAME
           pure_extension = lv_ext.
       TRANSLATE lv_ext TO LOWER CASE.

       IF lv_ext = 'png' OR lv_ext = 'gif' OR lv_ext = 'jpeg' OR lv_ext = 'jpg' OR lv_ext = 'bmp'.
         CREATE OBJECT cached_response
           TYPE
           cl_http_response
           EXPORTING
             add_c_msg = 1.
         lv_file_content = ls_image-data.
         cached_response->set_data( lv_file_content ).
         cached_response->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
         cached_response->set_status( code = 200 reason = 'OK' ).
***Set the Cache Timeout - 60 seconds - we only need this in the cache
***long enough to build the page and allow the IFrame on the Client to request it.
         cached_response->server_cache_expire_rel( expires_rel = 360 ).

         CALL METHOD cl_http_server=>get_location
           EXPORTING
             server       = cl_wdr_task=>server
           IMPORTING
             host         = lv_host
             port         = lv_port
             out_protocol = lv_protocol.

         CONCATENATE
           lv_protocol '://' lv_host ':' lv_port '/sap/bc/webdynpro/sap/'
           lv_guid '.JPG'
           INTO lv_url.

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

*         set single attribute
         lo_el_image->set_attribute(
           name `LINK`
           value = lv_url ).

         ls_img-id         = wd_this->gv_last_id.
         ls_img-img = ls_image-data.
         MODIFY zrao_img FROM ls_img.

Pls let me know the mistake that i made.

Best regards,

Narasimha.

former_member210804
Active Participant
0 Kudos

Hi

kindly give me some guidelines.

Best Regards,

Narasimha    

sahai
Contributor
0 Kudos

Hi,

you have all these three images in the mime repository.

Now to display these on screen you will obviously need  these to be bidden to an attribute. Since you need to dynamically decide which image among the three is to displayed, you can bind the attribute to the image ui element, and determine the value

former_member210804
Active Participant
0 Kudos

Hello ,

Thanks for your reply..but Your answer is not suites to my question.

I want to store the mime repository objects in my custom table.kindly see the above code...

Best regards,

Narasimha

sahai
Contributor
0 Kudos

Hi ,

what is the type of the table field you are using?

former_member210804
Active Participant
0 Kudos

Hi shitanshu,

Img field needs to store the images from the MIME repository of Webdynpro ABAP applications.

Best regards,

Narasimha.