0

我已经使用这个插件Angular Schema Form和所有的东西都按预期工作,但对于图片上传,我需要验证,以便允许用户只输入图片。角度模式表格图片上传接受所有文件类型

虽然架构包含接受的上传图片的属性属性如下:

{ 
"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"]} 

仍然是验证不会发生,我可以选择任何文件。

回答

0

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

对于图像I使用

“图案”:{ “mime类型”:“图像/ *} 接受所有图像

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