i All,
I am developing a Mobile App, where any picture i send from the Mobile Device to SAP comes in Base64 Encoded Format.
Now, when i decode it and pass the xstring to store the image. The image comes as a complete BLACK Picture.
IF o_mr_api IS INITIAL.
o_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).
ENDIF.
CONDENSE mimepath.
x = STRLEN( mimepath ) - 1.
IF mimepath+x(1) NE '/'.
CONCATENATE mimepath '/' INTO mimepath.
ENDIF.
CALL METHOD server->request->get_cdata
RECEIVING
data = lv_cdata.
CALL METHOD server->request->if_http_entity~get_form_fields
CHANGING
fields = lt_query_params.
READ TABLE lt_query_params INTO ls_query_params WITH KEY name = 'filename'.
IF sy-subrc = 0.
lv_filename = ls_query_params-value.
ENDIF.
IF lv_filename CS 'null'.
CONCATENATE sy-uzeit '.png' INTO lv_filename.
ENDIF.
CALL METHOD cl_http_utility=>if_http_utility~decode_x_base64
EXPORTING
encoded = lv_cdata
RECEIVING
decoded = lv_decoded_xstring.
IF lv_decoded_xstring IS NOT INITIAL.
l_content = lv_decoded_xstring.
CONCATENATE mimepath lv_filename INTO l_url.
TRANSLATE l_url USING '\/'.
CALL METHOD o_mr_api->put
EXPORTING
i_url = l_url
i_content = l_content
i_dev_package = '$TMP'
"i_suppress_package_dialog = 'X'
EXCEPTIONS
parameter_missing = 1 "i_new_loio = wa_file_loio-loio
error_occured = 2
cancelled = 3
permission_failure = 4
data_inconsistency = 5
OTHERS = 6.
IF sy-subrc = 0.
lv_json_output = 'The Photo was Uploaded Successfully to SAP'.
ENDIF.
ENDIF
CALL METHOD server->response->set_cdata( data = lv_json_output ).
.
Kindly, let me know if i should use any other method to decode and store images.
Thanks
Sahil