on 02-11-2009 5:45 AM
hi ,
I want to upload a file in Mime Repository.
Following is the code I have written for that.
I am bit confused with the URL and i think that is creating a problem
The file is not getting uploaded in the given path.
Help me in this regard whether URL given is right or there needs to be some changes.
Steps used are :
1. I am getting the File into the Context binded to File Upload Element.
2. Now i want to transfer the file present in the Context to the Mime.
3. For this I am transfering the context value into the path (URL) using Mime API but no data is getting transfered in the Mime Repository.
data: mime_repository type ref to if_mr_api,
content type xstring,
url type string value 'SAP/BC/WebDynpro/SAP/ZDOWNLOAD'.
DATA lo_el_context TYPE REF TO if_wd_context_element.
DATA ls_context TYPE wd_this->element_context.
DATA lv_content_fc TYPE wd_this->element_context-content_fc.
get element via lead selection
lo_el_context = wd_context->get_element( ).
@TODO handle not set lead selection
IF lo_el_context IS INITIAL.
ENDIF.
get single attribute
lo_el_context->get_attribute(
EXPORTING
name = `CONTENT_FC`
IMPORTING
value = content ).
mime_repository = cl_mime_repository_api=>get_api( ).
call method mime_repository->put
exporting i_url = url i_content = content .
Hi Reeha,
Regarding your file uploading problem, please check this code.
On a button action call this code to upload the file.
Please take care of the URL you going to pass.
The URL should be like this. i.e. You have to specific the dummy file name in the url as here in this example I am passing the Code.txt.
url TYPE string VALUE '/SAP/BC/WebDynpro/SAP/WDR_TEST_ADOBE_PDF_ONLY/CODE.TXT' .
METHOD onactiononclick .
DATA lo_nd_node TYPE REF TO if_wd_context_node.
DATA lo_el_node TYPE REF TO if_wd_context_element.
DATA ls_node TYPE wd_this->element_node.
navigate from <CONTEXT> to <NODE> via lead selection
lo_nd_node = wd_context->get_child_node( name = wd_this->wdctx_node ).
get element via lead selection
lo_el_node = lo_nd_node->get_element( ).
get all declared attributes
lo_el_node->get_static_attributes(
IMPORTING
static_attributes = ls_node ).
lo_el_node->set_static_attributes(
EXPORTING
static_attributes = ls_node ).
DATA:
mime_repository TYPE REF TO if_mr_api,
mime_type TYPE string,
url TYPE string VALUE '/SAP/BC/WebDynpro/SAP/WDR_TEST_ADOBE_PDF_ONLY/CODE.TXT' .
mime_repository = cl_mime_repository_api=>if_mr_api~get_api( ).
CALL METHOD mime_repository->put
EXPORTING
i_url = url
i_content = ls_node-data
i_language = sy-langu
EXCEPTIONS
parameter_missing = 1
error_occured = 2
cancelled = 3
permission_failure = 4
data_inconsistency = 5
new_loio_already_exists = 6
is_folder = 7
.
IF sy-subrc 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMETHOD. "onactiononclick
This will help you in solving your problem.
Regards
Manoj Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How I have done is this:
DATA: o_mr_api TYPE REF TO if_mr_api,
is_folder TYPE boole_d,
lv_current TYPE xstring,
lv_url TYPE string,
l_loio TYPE skwf_io.
IF o_mr_api IS INITIAL.
o_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).
ENDIF.
lv_url = '/sap/bc/bsp/sap/zapp/scripts/globallibrary.js' .
Now instead of bsp rename it to webdynpro, you can even check this in transaction SICF.
CALL METHOD o_mr_api->get
EXPORTING
i_url = lv_url
IMPORTING
e_is_folder = is_folder
e_content = lv_current
e_loio = l_loio
EXCEPTIONS
parameter_missing = 1
error_occured = 2
not_found = 3
permission_failure = 4
OTHERS = 5.
* convert string to xstring.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = go_jscript->gv_jscript
IMPORTING
buffer = lv_xstring.
o_mr_api->put(
EXPORTING
i_url = lv_url
i_content = lv_xstring
i_suppress_package_dialog = 'X'
i_new_loio = l_loio
EXCEPTIONS
parameter_missing = 1
error_occured = 2
cancelled = 3
permission_failure = 4
data_inconsistency = 5
new_loio_already_exists = 6
is_folder = 7
OTHERS = 8 ).
This should work fine for you.
I am not sure you have to convert string to xstring or not but I did it because I had string and had to convert it to xstring.
If useful points would be appreciated.
Thanks & Regards,
Abhinav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.