Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Validate Uploaded File

493904Oct 27 2010 — edited Oct 27 2010
Im my app users can upload files to a custom table using the file browse feature and some custom code.
I need to restrict the types of files they can uploaded, so I have created a validation on my page, that fires before the file is inserted into my custom table.
DECLARE
  l_mime_type     varchar2(20);

BEGIN
  select mime_type
  into l_mime_type
  from APEX_APPLICATION_FILES
  where NAME = :P41_FILE_NAME;
  IF l_mime_type NOT IN
('application/vnd.ms-excel',
'application/pdf', 
'application/msword',
'image/pjpeg',
'text/htm')
THEN
      delete from APEX_APPLICATION_FILES
      where NAME = :P41_FILE_NAME;
      commit;
     return 'Please only upload agreed file formats';
  END IF;
     return NULL;
  EXCEPTION
    WHEN NO_DATA_FOUND THEN
      return 'Please select file';
    WHEN VALUE_ERROR THEN
      return 'Please only upload agreed file formats';
END;
This fires when I press an upload button, so if the file is not the right type, then it will never reach my custom table.

It seems to work fine, apart from excel files, which are never loaded,ie, never pass the validation.

Any ideas appreciated

Gus
This post has been answered by jariola on Oct 27 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 24 2010
Added on Oct 27 2010
6 comments
711 views