Filename pattern

Last post 08-07-2012, 11:49 AM by Minisuit. 3 replies.
Sort Posts: Previous Next
  •  07-30-2012, 11:38 AM 74310

    Filename pattern

    Hello
     
    is it possible to restrict allowed filenames through a regex pattern like in the cuteeditor ?
     
     <security name="filenamePattern">^[a-zA-Z0-9\._-]+$</security>
     
    thanks, 
  •  07-31-2012, 8:24 AM 74319 in reply to 74310

    Re: Filename pattern

    Hi Luuuukke,
     
    You can limit the file name by your own logic in API "CuteWebUI_AjaxUploader_OnSelect" and use method Cancel() to remove it if not match your request. Please try the example below.
     
    "files" is the selected file list. files[i].FileName is the upload file name. 
     
    More detail about the API please refer to http://www.ajaxuploader.com/document/scr/JavaScript-API.htm 
     
    1. <%@ Page Language="C#" %>  
    2.   
    3. <%@ Register Namespace="CuteWebUI" TagPrefix="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    5. <html xmlns="http://www.w3.org/1999/xhtml">  
    6. <head id="Head1" runat="server">  
    7.     <title>example</title>  
    8. </head>  
    9.   
    10. <body>  
    11.     <form id="form1" runat="server">  
    12.         <CuteWebUI:UploadAttachments ID="uploader1" runat="server">  
    13.         </CuteWebUI:UploadAttachments>  
    14.     </form>  
    15. </body>  
    16. </html>  
    17. <script>  
    18. function CuteWebUI_AjaxUploader_OnSelect(files)  
    19. {  
    20.     for(var i=0;i<files.length;i++)  
    21.     {  
    22.         if(files[i].FileName=="181.gif")  
    23.         {  
    24.             files[i].Cancel();  
    25.         }  
    26.     }  
    27. }  
    28. </script>  
     
  •  07-31-2012, 10:04 AM 74323 in reply to 74319

    Re: Filename pattern

    Thanks, it works fine :)
     
    in case somebody needs it, here is a check with regex  to disallow whitespaces & special chars in file names
     
     <script>
         function CuteWebUI_AjaxUploader_OnSelect(files) {
             var re = new RegExp('^[a-zA-Z0-9\._-]+$');
             for (var i = 0; i < files.length; i++) {
                 var m = re.exec(files[i].FileName);
                 if (m == null) {
                     files[i].Cancel();
                     alert('The file "'+files[i].FileName + '" was not uploaded (unauthorized filename)');
                 } 
             }
         }  
    </script>
     
  •  08-07-2012, 11:49 AM 74364 in reply to 74323

    Re: Filename pattern

    A comma-separated list of regular expressions, used to filter the attachments by file name. Note that the parameter values must be regular expressions. For example:
    To match a file suffix of 'jpg', use .*jpg (not *.jpg).
    To match file names ending in 'jpg' or 'png', use .*jpg,.*png


    Best Regards,
    Navin Patel-Affiliate Manager
    Minisuit Affiliate Program
    Minisuit DOT com
View as RSS news feed in XML