使用 ng file upload 阻止上传 JavaScript 个文件

Prevent uploading JavaScript files with ng file upload

使用 ng file upload 指令我使用 ngf-accept 指定允许的文件类型列表。这不允许许多文件类型,它们在上传对话框中显示为灰色,但我仍然可以上传任何扩展名为 .js 或 .sh 的文件。

我已将指令添加到以下 link,以及允许的文件列表。

<a ng-model="file" data-nodrag ngf-select="openUploadModal($file, this)" ng-show="this.$nodeScope.$modelValue.type === 'folder'" ngf-accept="'image/*,video/*,audio/*,.pdf,.txt,.doc,.docx,.xls,.xlsx'">

问题来自 .txt 允许值。如果我删除“.txt”扩展名,.js 和 .sh 文件也会被禁用。显然 ,但有什么办法解决这个问题吗?

而不是 ngf-accept,尝试 ngf-pattern 然后你可以使用 '!'明确禁用某些文件类型:

<a ng-model="file" data-nodrag ngf-select="openUploadModal($file, this)" ng-show="this.$nodeScope.$modelValue.type === \'folder\'" ngf-pattern="'image/*,video/*,audio/*,.pdf,.txt,.doc,.docx,.xls,.xlsx,!.js,!.sh'">