Monday 7 February 2011

File Browse - filename length limit

I use the built in "File Browse" item in many of my applications and for a long time I had not experienced any issues. However, recently I noticed that there was an issue when using large filenames. If I selected a large filename and submitted the page a HTML error page was displayed. What surprised me was that this was not the usual APEX error page. After some investigation I found an interesting post on the APEX forums at Oracle.

http://forums.oracle.com/forums/message.jspa?messageID=2437324

It seems that there is a limit of 70 characters for the filename. It should be noted that this limit is solely for the filename, and does not include the path. This limit is purely down to how APEX internally stores the file in wwv_flow_files.

I have implemented the validation check described in the thread, with very slight changes to better suit my needs. The following is how I have done this.

Firstly I created the Javascript

<script type="text/javascript">
function checkFileName(pThis){
if (pThis.value != "") {
//get path value (including file name)
var fileAndPath = pThis.value;
//find the index of the last "\"
var lastPathDelimiter = fileAndPath.lastIndexOf("\\");
//get everything after the last "\"
var fileNameOnly = fileAndPath.substring(lastPathDelimiter+1);

if (fileNameOnly.length >70) {
alert("File name " + fileNameOnly +
" is too long. Filename can be maximum of 70 characters in length");
return false; //filename is not valid
}
else
return true; //filename is valid. so continue
}
}
</script>


In addition to displaying an error message if the filename is greater than 70, I decided to return a Boolean value to indicate whether the filename had passed the test or not.

This boolean could then be used along with a button to submit the page when the filename passed the test, or remain on the page if the name fails.

I created a button called UPLOAD with the following code within the URL Redirect.(F1_FILE_NAME is the name of the file browse item)

javascript:if(!checkFileName($x('P1_FILE_NAME')))return false;doSubmit('UPLOAD');


The above example is very simple but I think that implementing something similar is essential if the built in "File Browse" button is used in a production application.

Thank you goes to Mike and Arie for their examples in the aforementioned thread

0 comments:

Post a Comment

Apex Monkeys © 2008. Design by :Yanku Templates Sponsored by: Tutorial87 Commentcute Software blogs Computers Blogs