ngf-pattern不适用于ng-file-upload

时间:2015-12-07 07:34:25

标签: angularjs csv filter ng-file-upload

我正在尝试将文件类型限制为ng-file-upload组件中的CSV,但它无效 - 它仍然接受所有文件。

我已经尝试了ngf-pattern="'*.csv'"ngf-pattern="*.csv"

代码:

   <button class="btn btn-info" type="file" ngf-select="uploadFiles($file, $invalidFiles)"
                        ngf-pattern="'*.csv'" ngf-max-height="1000" ngf-max-size="1MB">
                    <i class="fa fa-upload"></i> {{'main.users.import.button' |translate}} </button>

相关性:

  "ng-file-upload": "~10.0.2",

2 个答案:

答案 0 :(得分:16)

尝试添加accept属性并删除*

<button class="btn btn-info" 
type="file" 
ngf-select="uploadFiles($file, $invalidFiles)" 
ngf-pattern="'.csv'" 
accept=".csv" 
ngf-max-height="1000" 
ngf-max-size="1MB">

编辑:接受没有单引号

答案 1 :(得分:1)

from flask import request

@app.route('/py', methods=['GET', 'POST'])
def server():
    if request.method == 'POST':
        # Then get the data from the form
        tag = request.form['tag']

        # Get the username/password associated with this tag
        user, password = tag_lookup(tag)

        # Generate just a boring response
        return 'The credentials for %s are %s and %s' % (tag, user, password) 
        # Or you could have a custom template for displaying the info
        # return render_template('asset_information.html',
        #                        username=user, 
        #                        password=password)

    # Otherwise this was a normal GET request
    else:   
        return render_template('main.html')

这对我有用!!谢谢@Michelem