我使用了这个插件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"]}
仍然没有进行验证,我可以选择任何文件。
答案 0 :(得分:0)
我安装了这个库:https://github.com/saburab/angular-schema-form-nwp-file-upload,它对我有用。
对于我使用的图像
“pattern”:{“mimeType”:“image / *} 接受所有图像。
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"
}
}