Search code examples
jqueryregexfile-uploadblueimp

acceptFileTypes Blueimp fileupload


I have implemented JQuery fileupload, but have a small issue with the accepted file types:

$('#fileupload').
    url: '/upload/uploaddoc', // URL zum File Upload
    type: 'POST',
    dataType: 'json',
    uploadTemplate: 'template-upload',
    acceptFileTypes: /^.*\.(?!exe$|lnk$)[^.]+$/i,
    maxFileSize:allowed_file_size
    .......
 }

I am using a regex to recognize the filetypes that are not allowed. But I want to pass a variable that contains the accepted file types just like in the maxFileSize but it does not seem to accept lists and strings.

Do you know what is actually passed to acceptFileTypes ?


Solution

  • You may use the RegExp constructor.

    Something like:

    acceptFileTypes: new RegExp("^.*\\." + my_condition_lookahead + "[^.]+$", "i"),
    

    Note that you need to double escape special regex meta characters when declaring a regex using constructor notation.