【问题标题】:angular schema form image upload accepting all file types角度模式表单图像上传接受所有文件类型
【发布时间】:2018-02-21 16:34:03
【问题描述】:

我使用了这个插件Angular Schema Form,所有的东西都按预期工作,但是对于图像上传,我需要进行验证,以便允许用户只输入图像。

虽然架构在图片上传的属性中包含 accept 属性,如下所示:

{
"type": "object",
"properties": {
    "text1": {
        "type": "string",
        "title": "Untitled Text field",
        "name": "text1",
        "url": "http://localhost/image/upload/img59b7c29f1622b.jpeg"
    },
    "file2": {
        "type": "object",
        "format": "file",
        "title": "Untitled image upload field",
        "x-schema-form": {
            "type": "file",
            "accept": "png|jpg|jpeg|gif"
        },
        "name": "file2"
    }
},
"image": ["text1"]}

验证仍然没有发生,我可以选择任何文件。

【问题讨论】:

    标签: javascript angularjs validation image-upload angular-schema-form


    【解决方案1】:

    我安装了这个库:https://github.com/saburab/angular-schema-form-nwp-file-upload,它对我有用。

    对于我使用的图像

    “模式”:{“mimeType”:“图像/*} 接受所有图像。

    My object is composed from:
    
    "image": {
                "title": "Image",
                "type": "array",
                "format": "singlefile",
                "x-schema-form": {
                    "type": "array"
                },
                "pattern": {
                    "mimeType": "image/*,application/pdf"
                },
                "validationMessage": [
                    "Only image and pdf",
                    "File must be small than 2MB"
                ],
                "maxSize": {
                    "maximum": "2MB"
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-15
      • 2021-11-27
      • 1970-01-01
      • 2010-11-01
      • 2020-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多