cancel
Showing results for 
Search instead for 
Did you mean: 

Reading File name, mimetype and size from FileUploadUIElement

Amey-Mogare
Contributor
0 Kudos

Hi,

I am using FileUploadUIElement and I need to read filename, type and size in my Button click action.

I have seen the standard Test UI elements component WDR_TEST_EVENTS which does this in wdDoModifyView method.

But is there any way to read them outside wdDoModifyView ? In a normal custom action event?

Thanks and regards,

Amey Mogare

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, Yes you can definately do the same in any of the custom events implemented. You will have to create a global attribute in the component controller say g_upload type ref to cl_wd_file_upload ( mark the Public checkbox ).

" Now in your view modify instead of, 
  file_upload2 ?= view->get_element( 'FILEUPLOAD2' ).
" you say,
    wd_comp_controller->g_upload ?= view->get_element( 'FILEUPLOAD2' ).
Now create an action for you button and copy the rest of the code from view modfiy and place it in this method, using wd_comp_controller->g_upload get the required values as follows.
* get the content of the filename property
  filename = wd_comp_controller->g_upload->get_file_name( ).

* get the content of the mime-type property
  mime_type = wd_comp_controller->g_upload->get_mime_type( ).

  wd_context->get_attribute( exporting name = 'FILECONTENT' importing value = filecontent ).
  size = xstrlen( filecontent ).
Regards, Radhika.

Amey-Mogare
Contributor
0 Kudos

Thank you Radhika!

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

This is absolutely NOT the recommended way of accessing these values. The direct interaction with the UI elements via coding in WDDOMODIFYVIEW should only used as a last resort for dynamically generated UI elements. You see this in some of the SAP test applications becuase of their dynamic nature. However this is NOT a best practice.

Instead you should data bind context attributes to the properties of the UI element. There are properties for fileName, dataType, and data:

http://help.sap.com/saphelp_nw70ehp1/helpdata/en/b3/be7941601b1d09e10000000a155106/frameset.htm

There is no reason to go through all this trouble of saving the instance of the UI element in component controller attribute and accessing programatically when you can just get the information from the context.

Amey-Mogare
Contributor
0 Kudos

Hi Thomas,

Thank you very much for this valuable suggestion!

With regards,

Amey Mogare

Answers (0)