How can I modify the ajax uploader's internal queue?

Last post 11-10-2010, 8:53 PM by Kenneth. 1 replies.
Sort Posts: Previous Next
  •  11-09-2010, 12:34 PM 64949

    How can I modify the ajax uploader's internal queue?

    Hi guys, I have a question I was hoping one of you could help me with.  Basically I am in a situation where I filter out files with bad extensions but when a file with a bad extension is encountered I don't just want to quit, I want to continue adding the good files that were selected so that they get built up in the queue but the bad files doesn't.  Here is a couple of snippets with the irrelevant stuff excluded:
     
    1.  // This event is fired after a user selects files to attach  
    2.         function CuteWebUI_AjaxUploader_OnSelect(files) {  
    3.  //change the files array would take no effect.  
    4.             var badExt = 'vbs|exe|bat|dll|ini|asp|url|js|pst';  
    5.             var name;  
    6.             var size;  
    7.             var ext;  
    8.             var temp;  
    9.   
    10.  for (var i = 0, l = files.length;  i < l; i++) {  
    11.                 name = files[i].FileName;  
    12.                 ext = name.substr((name.lastIndexOf('.') + 1));  
    13.   
    14.                  if (badExt.indexOf(ext) != -1) {  
    15.                     alert(ext + ' is not an allowed file type.');  
    16.                     return false;  
    17.                 }  
    18. }  
    19. return true;  

     
     So currently if a bad extension is encountered the event returns false.  This causes the other files that were selected along with the bad file to not be built in the queue. 
     
    So is there a way to not return false but still prevent the bad file from being queued up to be uploaded?
     
    I have a couple of other situations where I am basically having to parse the file out on the server side.  I would rather avoid having to upload the file at all mainly because I do not want the progress bar showing a bad file being uploaded.  Thanks for your help!
     
    Stewart
     
  •  11-10-2010, 8:53 PM 64966 in reply to 64949

    Re: How can I modify the ajax uploader's internal queue?

    Hi ssoutrs,
     
    Please try the example below
     
    1. <%@ Page Language="C#" Title="Customize the queue UI" %>  
    2.   
    3. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">  
    5. <html xmlns="http://www.w3.org/1999/xhtml">  
    6. <head id="Head1" runat="server">  
    7. </head>  
    8. <body>  
    9.     <form id="Form1" runat="server">  
    10.         <CuteWebUI:UploadAttachments ID="Uploader1" runat="server">  
    11.         </CuteWebUI:UploadAttachments>  
    12.     </form>  
    13. </body>  
    14.   
    15. <script>  
    16.   
    17. var uploader=document.getElementById("<%=Uploader1.ClientID %>");  
    18.   
    19. uploader.handlequeueui=myqueueuihandler;  
    20.   
    21. function myqueueuihandler(list)  
    22.   
    23. {  
    24.    for(var i=0;i<list.length;i++)  
    25.        {  
    26.           var badExt = 'vbs|exe|bat|dll|ini|asp|url|js|pst';   
    27.           var name=list[i].FileName;  
    28.           ext = name.substr((name.lastIndexOf('.') + 1));    
    29.   
    30.           if (badExt.indexOf(ext) != -1) {    
    31.                  list[i].Cancel();    
    32.                 }    
    33.         }  
    34.  }  
    35. </script>  
    36.   
    37. </html> 

     
    Regards,
     
    Ken
View as RSS news feed in XML