文件上传acceptfiletypes选项

时间:2017-05-13 09:44:23

标签: javascript c# regex asp.net-mvc-4 blueimp

我在ASP.net MVC应用程序中使用Blueimp Fileupload, 我需要在运行时构建RegEx acceptfiletypes选项以接受 mime类型捕获所有可能的Office MIME文件类型,如:

        private readonly HttpListener _httpListener;

            if (!HttpListener.IsSupported)
        {
            throw new NotSupportedException(
                "The Http Server cannot run on this operating system.");
        }

        _httpListener = new HttpListener();
        _httpListener.Prefixes.Add(prefix);
        _sessionSettings = settings;

1 个答案:

答案 0 :(得分:0)

使用此正则表达式来测试您的mimetype是否为Microsoft应用程序。它基于this document列出大多数mime类型:

const officeRegex = /application\/.*?(?:msword|x-ms|vnd\.ms-|officedocument)/; const mimeTypes = [ "application/msword", "application/pdf", "image/png", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ]; mimeTypes.forEach(function(mimeType) { console.log(officeRegex.test(mimeType)); });

Demo

示例代码段

{{1}}

相关问题