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