cancel
Showing results for 
Search instead for 
Did you mean: 

Limit FileUpload to certain filetypes

mike_mcinerney
Participant
0 Kudos

     Is there a way to limit the Browse on a file upload to only go after certain types, in my case, PDFs ?

Accepted Solutions (0)

Answers (3)

Answers (3)

mike_mcinerney
Participant
0 Kudos

Thanks for all the followon info - I'm going to close this question - Just to clarify, the question was can we somehow (proactively) only allow the user to select certain filetypes - and I think the answer is "No". 

Thanks all...

...Mike

0 Kudos

  In FILEUPLOADUI  Upload Event

------------------------------------------

  lv_file_upload ?= wd_this->mr_view->get_element( 'FILEUPLOADUI' ).

* get the content of the filename property

  lv_filefullname = lv_file_upload->get_file_name( ).

*  call function 'SO_SPLIT_FILE_AND_PATH'
*    exporting
*      full_name     = lv_filefullname
*    importing
*      stripped_name = l_filename_ext.

call function 'Z_HR_ATTACH_SPLIT_PATH'
  exporting
    l_filenam_w_path       = lv_filefullname
importing
*   E_PATH                 = E_PATH
   e_filename             = l_filename_ext .
*   E_SERVER               = E_SERVER          .

split  l_filename_ext at '.' into: l_filename l_ext_name .


call function 'Z_HR_CHK_ATTACH_EXT'
  exporting
    i_ext          = l_ext_name
importing
   e_ok_ext       = l_ok_ext        .

  if  l_ok_ext   = space.
    lv_msg-msgty = 'E'.
    lv_msg-msgid = 'ZHR'.
    lv_msg-msgno = '727'.
    lv_msg-msgv1 = 'File extension ' .
    lv_msg-msgv2 = l_ext_name .
    lv_msg-msgv3 = ' not allow' .
    lv_msg-msgv4 = space .
*   report message

    elem_context->set_attribute_null('DATA' ).

    call method wd_comp_controller->mo_message_manager->report_attribute_t100_message
      exporting
        msg            = lv_msg
        element        = elem_context
       attribute_name = 'DATA'.
  endif.

former_member184578
Active Contributor
0 Kudos

Hi,

Yes, It is possible. Create an attribute mime_type in context and bind the mime_type property of the file upload UI to that attribute. After browsing and selecting the file path and on click of Upload button, Read the mime type and display an error message if it is not the required type. for pdf mime type will be 'application\pdf' i guess.

Or,

bind the file name property of file upload UI to an attribute( file_name), read the file name in the onAction of upload button and read the file extension ( last occurrence of . dot) . and display error if it is not required type.

Hope this helps u.,

Regards,

Kiran

mike_mcinerney
Participant
0 Kudos

Thank you Kiran,

Yes, that is what I presently have coded (and yes,it is appliaction/pdf).

I was wondering if there was a way to only allow the user to select files of a certain mimetype.

I'd like to limit the selection, not warn them afterwards.

Former Member
0 Kudos

I think the poster wanted the file upload control to limit the file type to *.pdf for example, so that only those files are shown for the user to choose from. I'm not aware that it's possible. The file upload control will remember the previous setting but to default it, some fancy scripting would have to take place to which there probably isn't any interface in WDA. That said there are even differencies in how different browsers work.

former_member184578
Active Contributor
0 Kudos

Hi,

As far I knew there is no such provision in WDA as we cannot use Script. And even though if we set the file type say *.pdf, the user may change the file type to All files (* ) in the file open dialog.

So we can warn the user only after uploading.

Regards,

Kiran