Checking filename length in File Browse item before uploading

I have a File Browse item from which users can upload files into the database. Within APEX, the file metadata and content first get uploaded into the view WWV_FLOW_FILES. By design apparently, the underlying table for this view has a NAME field which is limited to 90 characters. I would like to test the length of the Name field and provide a warning to the user if the name exceeds 90 characters, but any validation I write to that effect does not "fire" until after the file has been uploaded to the WWV_FLOW_FILES view. That attempt to upload apparently is the first thing that happens when you Submit with a File Browse item, even before the validation. If the name of the file exceeds 90 characters in length, the attempted upload errors out with a generic Page Not Found error. Is there any way to capture the length of the Name of the file with a File Browse item prior to the attempt to upload to the WWV_FLOW_FILES view, or is my only option just to put a warning banner on the page?

Hello Mike,
>> Column NAME in WWV_FLOW_FILES is VARCHAR2(90). It does not include the local filename path. It include a prefix like "F1521676842/" in the front of the filename.
Yes, you are correct. I spoke from memory, and it seems that I remembered one of my customized tables, where I also save the local full path of the file.
As far as I can see in my system, the extension of the ‘F123….’ is not with a fix length, and the highest one is 18 characters long. Therefore, it seems that the actual file name should be less than 70 characters long.
A similar code to the following can be used in a validation check:
<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 (" + fileNameOnly.length + " characters).");
      pThis.focus();
</script>The “HTML Form Element Attributes” of the item should include:
onblur=" checkFileName(this)"
Regards,
Arie.

Similar Messages

  • How to populate DB column with filename from file browse item?

    Hi,
    Using APEX 3.1.2, I'm trying to easily allow maintenance of a filename stored in a DB column (VARCHAR2(1000)). Using the column as a file browse item seemed to be the way to go, but of course I don't want the resulting file to be uploaded and it appears as though an existing filename is not shown in a form when the row is retrieved.
    After much searching, I found Checking filename length in File Browse item before uploading , but I'm not able to connect the dots. I was thinking that I could create a hidden file browse item and use a button to call Javascript function to activate it, then save the resulting filename to my DB column item and wipe out the hidden item before it was uploaded. But the hidden item doesn't appear, so I'm not able to reference it's form input name.
    Hopefully this mess makes sense. Anyone?
    Thanks!
    Rich
    Edited by: socpres on Sep 5, 2008 2:02 PM because message was truncated after attempting to preview it first.

    Hi John,
    From what I can tell, the path of a local file browsed from a file browse item cannot be retrieved because of security concerns. Although, it seems that while Firefox 3 only returns the filename sans directory, IE6 returns the full path:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
    <head><title>Form Test</title>
    </head><body>
    <script type="text/javascript" language="JavaScript">
    function GetDirectory()
    strFile = document.FileForm.filename.value;
    intPos = strFile.lastIndexOf("\\");
    strDirectory = strFile.substring(0, intPos);
    alert(strDirectory);
    document.FileForm.Directory.value = strDirectory;
    </script>
    <form id="FileForm" name="FileForm">
    <input type="file" id="filename" name="filename" value="" onChange="GetDirectory(this.value)">
    <input type="hidden" id="Directory" name="Directory" value="">
    </form>
    </body>
    </html>
    This Win-specific code displays the path via IE6, but not in Firefox 3. Then again, I can't seem to preview posts here using FF3, either...
    Rich

  • Open Cursor Issue because of file browse Item - Is this a Bug in APEX 3.2

    Hi All,
    I am using file browse Item to upload file into the database at two places in my application, but it seems whenever I am submitting those two pages, with file path or without file path, its opening an cursor which remains open after that, because of this open cursor count in the application is getting exceeding every time.
    For testing this I have made an dummy page containing just file browse item and submit button, and still it is increasing the open cursor count.
    Is this a bug in Apex file browse item or there is some other way to handle this.
    Please kindly help me in the above issue as this is affecting the production application.
    Thanks & Regards
    Sanjay
    Edited by: user11204334 on Dec 5, 2010 9:57 PM
    Edited by: user11204334 on Dec 5, 2010 9:58 PM

    Hi,
    One observation, Apex is switching the Session ID after one got killed ? I was working on Apex page with browse Item to test open cursor count,
    after killing the SID (227) on which the open cursor count was getting increase, it APEX automatically switches to new SID(149) for that session.
    Now the problem is even if I have two SID's and one hits the maximum open cursor count, It is not switching to other SID instead the whole application becomes unavailable.
    STATNAME SID VALUE USER
    opened cursors current 20 14 APEX_PUBLIC_USER
    opened cursors current 149 74 APEX_PUBLIC_USER
    opened cursors current 194 71 APEX_PUBLIC_USER
    opened cursors current 211 5 APEX_PUBLIC_USER
    opened cursors current 227 325 APEX_PUBLIC_USER Killed
    opened cursors current 244 15 APEX_PUBLIC_USER
    opened cursors current 20 14 APEX_PUBLIC_USER
    opened cursors current 149 76 APEX_PUBLIC_USER
    opened cursors current 194 71 APEX_PUBLIC_USER
    opened cursors current 211 5 APEX_PUBLIC_USER
    opened cursors current 244 15 APEX_PUBLIC_USER
    Please kindly help in this.
    Thanks in Advance
    Thanks & Regards
    Sanjay
    Edited by: user11204334 on Dec 8, 2010 1:02 AM

  • APEX 2.2 - File Browse item maximum file length?

    Hi all,
    There seems to be a maximum length for file name (not path - just the name) that can go into APEX through the File Browse item. I have a file name that is 206 characters long. Even if I put the file in the root directory, when I try to upload it to my APEX application, I get a 404.
    What is the maximum file name length?
    Not relatedly, IE6 balks when the file path length exceeds a certain amount. It doesn't attach the file to the file input HTML element. Does anyone happen to know what that length is?
    Thanks!

    Don - See Re: Upload File with filename greater 80 characters -> HTTP 404 File not fo for related info.
    Scott

  • How to set "Files of type" when using a "File Browse" item.

    Apex 4.0.2
    Internet Explorer 7 +
    I have a "File Browse" item on a page and need to limit the types of files display to just "text (.txt)" files. How can this be done? Currently, the "Files of type" list shows "All File (*.*)", "Pictures (*.gif,*.png)", and HTML (*.htm,*.html)". In the best case, I would like to not have the "Files of type" list and have the user just limited to text files. However, adding Text files (*.txt)" to the "Files of type" list is ok.
    thanks,
    William

    Thought i'd do a bit of research after seeing Scotts wonderful ideas.
    So it turns out, IE made the file item read only from version 8, for security reasons. Read more: http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
    File Upload Control
    Historically, the HTML File Upload Control (<input type=file>) has been the source of a significant number of information disclosure vulnerabilities. To resolve these issues, two changes were made to the behavior of the control.
    To block attacks that rely on “stealing” keystrokes to surreptitiously trick the user into typing a local file path into the control, the File Path edit box is now read-only. The user must explicitly select a file for upload using the File Browse dialog.
    Additionally, the “Include local directory path when uploading files” URLAction has been set to "Disable" for the Internet Zone. This change prevents leakage of potentially sensitive local file-system information to the Internet. For instance, rather than submitting the full path C:\users\ericlaw\documents\secret\image.png, Internet Explorer 8 will now submit only the filename image.png.To resetting the actual items, suggestions I found were to replace the actual item. So instead of using $s, I just replace the element, with the existing element, causing it to re-initialise.
    var htmldb_delete_message='"DELETE_CONFIRM_MSG"';
    function fileCheck(el){
        if(el.value){
            var validFile = false;
            var validExtensions = ["csv"];
            var filename = el.value;
            var fileExtIndex = filename.lastIndexOf(".");
            var fileExt = filename.substring(fileExtIndex+1, filename.length);
            for(i = 0; i < validExtensions.length; i++){
                if(validExtensions[i] == fileExt){
                    validFile = true;
                    break;
            if ( !validFile || fileExtIndex == -1) {
                alert("Invalid Extension. Permitted files must end with: " + validExtensions.toString());
                var htmlContents = el.outerHTML || new XMLSerializer().serializeToString(el);
                $('#P16_BINARY').replaceWith(htmlContents);
    }(obviously, replacing what you need to, to suit your page - i prefer scotts idea of passing in supported file types in the function, so would just pass in an array instead; but this is just for demonstration)
    with an onchange="checkFile(this)" on the element attributes.
    On a slightly un-related note, I found out IE doesn't support the wonderful indexOf function on arrays, that checks for the existence of the value in an array. Sucks.
    Edited by: trent
    Ah well, jQuery is there, maybe i should use that for searching arrays in the future.
    http://api.jquery.com/jQuery.inArray/
    Edited by: trent
    Forgot a demo link, for csv files: http://apex.oracle.com/pls/apex/f?p=45448:16
    Edited by: trent
    Modify function. Didn't work in Firefox

  • How to get full path in file browse item

    Hi
    I have a file item. When I submit the form and store and value in db, then the file path is stored as numbers and appended to the file name. I undestand that this is because of some wwv flow files index or something . How to get the file path? Anybody...

    For security/privacy reasons recent versions of browsers by default do not send local file path information from File Browse items to the server, nor expose the file path in the control's JavaScript methods. Firefox, Safari and Chrome only provide the filename. IE6 & IE7 still yield the path in Windows format. IE8 and Opera have adopted an irritating approach of replacing the path with a wholly imaginary "C:\fakepath\".
    Changes to IE's security config can enable the path to be exposed in IE8, but I don't think it will be available via <tt>apex_application_files</tt>.
    For more information see:
    http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-March/018980.html
    http://blogs.msdn.com/ie/archive/2009/03/20/rtm-platform-changes.aspx

  • How to know if a file browser item is not null using javascript fucntion

    Hi
    <br><br>
    I tried to use javascript for validation. I have a file browser item named P55_FILE_NAME and I would like to know if this item is null or not before submit.
    <br>
    I wrote this function :<br><br>
    function validate_import(f_n){<br>
         if (trim(document.getElementByName(f_n).src) == "")<br>
         {<br>
         alert ("File name is empty.");<br>
         document.getElementByName(f_n).focus();<br>
         }<br>
         else{<br>
         doSubmit('SUBMIT');<br>
         }<br>
    } <br><br>
    When I press submit button I got an error, sounds like the src method does not exist in my input item. <br>
    Then, I looked my source page an I found this :<br><br>
    input type="file" name="p_t01" size="30"
    <br><br>
    there is know src method and the name is not P55_FILE_NAME and I don't want to use <b>p_t01</b> that will change.<br>
    <br>
    I need your help.<br>
    Benn

    Hello,
    The p_txx notation is the internal name the ApEx engine attaches to each page item. It starts with p_t01 (for the first item on page) and can end with p_t99 (hence, the max 99 items per page limit). You can see these names in your HTML source code.
    The bug in the File Browse item (fixed in version 2.2) is that the ID of the item is the internal name instead of the item name. Hence, in order to use DOM, you need to use this internal notation.
    If the File Browse item id is p_t01, you can null its content by using something like that (V2.0 notation) :
    html_GetElement('p_t01').value = '';I'm using the same, and similar code, for manipulating this type of item with no problems.
    Please document the use of this workaround, as when you'll upgrade your ApEx system, you will have to change this code back to the standard – item id equal item name.
    (Please follow Scott's advise, and keep your logic connected issues on the same thread. It will get you more quick and accurate help).
    Regards,
    Arie.

  • Different issues with file browse item

    Hi everybody,
    I'm trying to create a file upload page using the file browse item. To achieve this I followed the how-to document :
    http://download-west.oracle.com/docs/cd/B19306_01/appdev.102/b16376/up_dn_files.htm.
    I've created my own table to store the documents as I store some extra information.
    When I test this functionality I discovered many issues.
    - If I upload a PDF file this gives me HTTP 404. When I go back, choose the same file with the browse button and upload again this will pass.
    - If I upload a file with spaces in it's name this file will be uploaded twice. (I see the same file two times in the table with 2 different names.
    - At random times I will just arrive at a blank page after clicking the upload button. It appears to me as this will happen more often when I use a double-click to select the file in the browser dialog compared to selecting the file and clicking open. However, I suppose this is just coincidence. It happens in both cases. I'm confronted with the problem with small files (1k, 4k) as well as with larger files (6m)
    - Like I said before, I store some extra information as well. In some cases this information is stored with the document. In some other cases he takes the description from a previous document to store along with the new document. I suppose this is some kind of session problem probably caused by the other problems I currently have and the fact I press back quite often in my browser (each time I arrive at a blank page)
    Version of HTML DB 2.1.0.00.05
    (Included with Oracle 10g express edition)
    I read several posts on this forum before creating my own thread.
    -> I found several discussions about the size of the file but the problem exists for files of 1K as well so I don't see a link with those discussions.
    -> I found several discussions about security and tablespace quota. I granted unlimited tablespace to each and every user : flows_020000, flows_020100, flows_files, htmldb_public_user and the user who is used in the application.
    Tx very much for your help!
    Kris

    Hi Kris,
    I think you're problem is coming from local session info... using the back button is not that good. Put a back button in your application ;-)
    An other thing I wonder is; are you developing and testing on the same machine and at the same time? - I did that before and that gave me some problems. Now I'm developing in Firefox and test with IE or vice-versa.
    Dimitri

  • Using  File Browse Item To Get File Only

    Is it possible to use the file browse item to just get the file without inserting it anywhere?
    I'm looking to allow a user to "upload" a file from their client machine... but what will actually happen in the process is it will take the file and send it in an e-mail to whomever needs to get it.
    Or is the only way to allow it to insert the file, do what I need to do with it, and then immediately delete it?
    Thanks,
    Chad

    Hello Chad,
    Please check if the following can help you - Using the file browser. .
    Regards,
    Arie.

  • Modifying File Browse item through Javascript

    I would like to modify the value of a File Browse item with javascript in my Submit button under certain circumstances. I would like to remove the file name (and path) from the File Browse field, so that the file is not automatically uploaded when the Submit button is pressed. It would seem I could "null" out the filename within the javascript function and then follow that with doSubmit ('SUBMIT'). The rest of the page values would be posted to the database, but the file would not get loaded. However, I cannot figure out how to access and modify the filename in the File Browse field with javascript. I've tried using ".value" and ".src" but to no avail. Saw a thread that says there is a bug with File Browse items in versions earlier that 2.2 (I'm using 2.0), and that you needed to fall back on the "p_t xx" notation, but I can't find any information on what that is. Appreciate any help.

    I apologize for the multiple threads. The response to my initial inquiry on thread Inserting/uploading data without inserting/uploading a document was that "others" would be better equipped to help me than the initial responder, so I didn't think I was supposed to continue with that thread. (Haven't used this forum much.) I found a second thread (the one with the "p_tXX" notation, and responded to it, but wasn't sure if all older threads were still active, so I also iniitiated a thread on my own.
    In response to the inquiry about why not using an after submit computation to null out the File Browse item, what I am trying to prevent is the uploading of a file to the WWV_FLOW_FILE_OBJECT$ table, if there is an entry in my File Browse item, when all the user really wants to do is update some data items on the main portion of the page. I have a Apply Changes button on the main data entry form, and then I also have (at my user's request) a separate form and Submit button on the page where the user may enter a file name to upload. The trouble exists when the user is only trying to modify data in the main form, but has also left an entry in the File Browse item. When the page is submitted, the data is uploaded OK, but the file is also uploaded via HTMLDB_APPLICATION_FILES, since there is an entry in the File Browse item. What I'm trying to do, is clear that File Browse item out when the user presses the main form Apply Changes button, so that the file does not get uploaded. The users want the ability to upload a file, but only when that is their direct intent. Obviously, I do not want to clear out the File Browse item under those circumstances. Hope this is clear; sometimes difficult to satisfy the users needs (whims?). Appreciate any help.

  • File in File Browse item disappears if validation fails on any item ....

    Greetings:
    I'm using APEX 4.0. I have a region with 7 data elements, one of them being a File Browse page item. The BLOB file loads in the WWV_FLOW_FILES table first, then in the "After Submit" page processing, I move the BLOB into my own custom table. This works great in normal processing.
    However, if any of the other data elements in this region fails validation, the page renders with the validation messages, but the file in the File Browse page item disappears. Therefore, the user would have to re-select the file to upload before they resubmit and process the page again.
    How can I avoid this? Why does the path and file name disappear when page validation fails?
    Thanks,
    Stan

    bondurs wrote:
    Greetings:
    I'm using APEX 4.0. I have a region with 7 data elements, one of them being a File Browse page item. The BLOB file loads in the WWV_FLOW_FILES table first, then in the "After Submit" page processing, I move the BLOB into my own custom table. This works great in normal processing.
    However, if any of the other data elements in this region fails validation, the page renders with the validation messages, but the file in the File Browse page item disappears. Therefore, the user would have to re-select the file to upload before they resubmit and process the page again.
    How can I avoid this? Why does the path and file name disappear when page validation fails?It is a required security feature. Per the HTML specification, APEX will not render a value in a file browse item on page show. This protects the user from nefarious persons changing the file item value during spurious "failed" validation (hoping the user is distracted correcting the "failed" item and does not notice) in order to capture a file the user does not intend to submit (e.g. /etc/passwd).

  • File Browse Item in APEX versions prior 4

    Hi there,
    we are currently struggling with a strange issue concerning the File Browse Item in earlier APEX versions: The item value is not submitted correctly when using APEX Listener. There is always a F<randomnumber>/ as prefix that is not visible anywhere in the page source code (so it's not generated by APEX itself) or browser (Firebug trace didn't see any prefix transmitted) and this value is even there when the file browse dialogue is submitted empty. The latter case causes severe problems, as validations fail to detect null values. Our current workaround is a regex on that prefix, but this obviously is no clean solution.
    We found out that F<randomnumber>/ is the prefix of the name that is created temporarily in WWV_FLOW_FILES. If submitted correctly, the name is prefix + actual filename.
    This problem does not occur when using OHS and it does not occur when running the APEX Listener on top of APEX 4.0.2.
    The problem occurs reproducible in the following environments:
    - APEX Listener 1.1.2 standalone or any JEE Container, JDK 1.6.0_26, Linux or Windows
    - APEX 3.1.2 or APEX 3.2.1
    The problem seems to be related to the one discussed in {thread:id=2205973}, but describes some different effect that is not reproducible on OHS.
    I appreciate every clue where this may come from and any hint on how to turn it off...
    Thanks,
    Udo

    Hello Claudio,
    After reading this story, I have same problem with version 1.1 of the apex listener and version 4.1 application express.I still think it affects only versions prior to 4.0. I'm not able to reproduce it on 4.1.
    How do I resolve this problem?I think you ran into a bug in GlassFish 3.1.2. This has been discussed and resolved here: {thread:id=2357381}
    I hope this helps you solve your problem.
    -Udo
    P.S.: Please always open a new thread if you are not sure you are in the same situation and especially when the original thread is long "dead" like this one. Of course you can reference other threads with possibly similar issues in your thread.
    Thanks!

  • Weird problem while Extracting File path from file Browser item

    Hi all
    I followed some tutorials on this forum to get the absolute filepath from the filebrowser item and storing it in the database.
    Heres what I did. I created a script in the header of the page which reads like this:
    <script language="JavaScript1.1" type="text/javascript">
    function SaveFullName(filepath,feed)
    function getVal(item)
    if(document.getElementById(item).value != "")
    return document.getElementById(item).value;
    else
    return "";
    document.getElementById(filepath).VALUE = getVal(feed);
    alert(document.getElementById(filepath).VALUE);
    </script>
    I have call this function by this syntax which I have put in the onchange event handler of the file browser item.
    onChange="javascript:SaveFullName('CCDPATH','CCDFILEBROWSER');"
    Here CCDPATH is the name of the hidden item which I use to store the path and CCDFILEBROWSER is the name of the filebrowser in question.
    now the last statement of the script above, alert(), gives me an alert with the proper value. The problem is when I am trying to store the value of this variable CCDPATH in my database with an onsubmit process, NULL values are getting inserted :-(
    When I checked out in the debug mode, I can see that the value of this hidden item, CCDPATH is showing as "" , i.e; null. Why is this happening is out of my understanding.
    I mean, with the javascript, it is assigning and displaying its value perfectly, but when I try to store it with PLSQL, it simply does'nt happen.
    What am I possible doing wrong? What should I do to store the value of this hidden item in the database ??

    Any thoughts people?

  • Capture onclick event on the Download Link of a File Browse Item

    I'm using APEX 4.0.1 and need to create a javascript:popupURL after a file browse item's onClick event fires and before the download dialog popup appears.
    Here's a related thread: {thread:id=2135877}
    Is this possible to do? If so, any help will be appreciated.
    Edited by: CM Randy SD on Jan 11, 2011 7:54 AM

    >
    I tried each of the following in the the Element HTML Form Element Attributes for the File Browse item:
    onClick=javascript:alert(this.value);
    onClick=javascript:popupURL('http://www.google.com');
    onFocus=javascript:alert(this.value);
    onChange=javascript:alert(this.value);And what happened?
    [A few points on good practice:
    1. In the XHTML normally used in APEX 4.0 mark-up, all XHTML, including attribute/event handler names, should be in lower case: <tt>onclick</tt>, <tt>onfocus</tt>, <tt>onchange</tt>...
    2. Attribute values should always be quoted.
    3. The <a href="http://crisp.tweakblogs.net/blog/313/the-useless-javascript-pseudo-protocol.html">"javascript:" pseudo-protocol is evil</a>. There are a few places in APEX where we may have to resort to using it as URL is all we're offered to work with, but it's always better to use an event handler of some kind, either inline or (better) registered dynamically at runtime following the principles of <a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript">unobtrusive JavaScript</a>. +It absolutely should not be used in inline event handlers.+
    So:
    {code}
    onclick="alert(this.value);"
    etc

  • How stop File Browse item losing value when a validation occurs

    G'Day Apex gurus,
    I am using Apex 3.1.0 and Firefox in an XP PC and have a file browse page item on my page but whenever i experience a validation error on the page, the value entered into this box is lost.
    Every other field on the page retains its entered value, but the file browser item loses its value.
    This is frustrating because the user will have to reselect the file.
    Is there a way to retain the value upon a validation error?
    I appreciate any assistance with this
    Carlos

    Hey creyes,
    I don't think this is possible.
    Because of security implications (scripts setting the value, and then attempting to retrieve files of your computer) the value of the fileupload form field is read only. Therefore you cannot set, or reset the value.
    A solution could be that you make validations with javascript if possible (but keep validations on the database side also!).
    Kind regards,
    Oli

Maybe you are looking for