【问题标题】:Prevent uploading JavaScript files with ng file upload使用 ng file upload 防止上传 JavaScript 文件
【发布时间】:2017-05-16 17:40:00
【问题描述】:

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

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

<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 文件也会被禁用。显然是this is due to a bug affecting Mac users only,但是有什么办法解决这个问题吗?

【问题讨论】:

  • 请注意,该插件不会阻止用户跳过您的客户端保护并通过同一端点将您的服务器允许的任何内容直接上传到服务器。
  • 是的,我有服务器端保护,但希望避免那些不使用 API 的人出现客户端错误

标签: angularjs ng-file-upload


【解决方案1】:

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

<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'">

【讨论】:

    猜你喜欢
    • 2016-11-09
    • 2015-04-02
    • 2017-08-16
    • 2016-01-08
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多