cancel
Showing results for 
Search instead for 
Did you mean: 

File upload doesnot working in a new view created in ICWC

raja_g
Participant
0 Kudos

Hi,

I created a new view and controller similar to MailAttachment controller. The file upload is not working.

In the layout, the following code is added

<htmlb:fileUpload id = "myFileUpload2"

size = "30" />

In my new controller class, the following code is written to do file upload

Data: lv_id type string,

data1 type ref to cl_htlmlb_fileupload.

lv_id = me->get_id( 'myFileUpload2' ).

data1 ?= CL_HTMLB_MANAGER=>GET_DATA( request = runtime->server->request name = 'fileUpload' id = lv_id ).

On executing, Data1 doesn't contain the uploaded file details.

In the method IF_HTMLB_DATA~RESTORE_FROM_REQUST of class CL_HTMLB_FILEUPLOAD, the num_multiparts is always returned as 0.

num_multiparts = request->num_multiparts().

Thanks

G.Raja

Accepted Solutions (1)

Accepted Solutions (1)

maximilian_schaufler
Active Contributor
0 Kudos

As a first guess, I would check if the submitted data is dispatched to your (sub-)controller in the right way.

If you are using sub-controllers, make sure you call dispatch_input( ) in your main controller.

If you debug into that part of the code - can you read some other submitted data?

Answers (1)

Answers (1)

SudheerHarman
Advisor
Advisor
0 Kudos

Is data1 is coimg as initial?

Please check with following code.

method GET_UPLOADED_DATA.

DATA: lv_file_length TYPE string,

lv_file_mime_type TYPE string,

lv_file_name TYPE string,

lv_file_content TYPE xstring,

lv_prefix_field TYPE string,

lv_upload_ctl_id TYPE string,

lr_cx_vsi TYPE REF TO cx_vsi,

lv_fileupload_class TYPE REF TO cl_htmlb_fileupload,

lv_colsize TYPE i,

lv_string_value TYPE string,

lv_default type bool value abap_true.

DATA: lv_msgsrv TYPE REF TO cl_bsp_wd_message_service.

lv_msgsrv = cl_bsp_wd_message_service=>get_instance( ).

  • Get the page prefix. Used to find the real formid for the upload control

lv_prefix_field = request->if_http_entity~get_form_field( 'AOEU_ZZZ_PREFIXID' ).

CONCATENATE lv_prefix_field 'myUpload' INTO lv_upload_ctl_id.

TRY.

  • Get uploaded file data from htmlb control

lv_fileupload_class ?= cl_htmlb_manager=>get_data(

request = request

id = lv_upload_ctl_id

name = 'fileUpload' ).

CATCH cx_vsi INTO lr_cx_vsi.

handle_upload_exceptions( iv_vscan_msg = lr_cx_vsi ).

"@TODO restore this return.

RETURN.

ENDTRY .

  • Grab useful properties of the upload

lv_file_name = lv_fileupload_class->file_name.

lv_file_mime_type = lv_fileupload_class->file_content_type.

lv_file_length = lv_fileupload_class->file_length.

lv_file_content = lv_fileupload_class->file_content.

  • If empty, throw an error

IF lv_file_name IS INITIAL.

  • Throw empty file warning

lv_msgsrv->add_message( iv_msg_type = 'E'

iv_msg_id = '/CRMXP/CRM_UM_UI'

iv_msg_number = '006' ).

exit.

ENDIF.

DATA: lt_csv_contents TYPE TABLE OF string,

conv TYPE REF TO cl_abap_conv_in_ce,

len TYPE i.

  • Convert XSTRING to String and UTF-8 using correct codepage

ev_content = cl_sam_toolkit=>XUTF82S( lv_file_content ).

endmethod.