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이 라이브러리를 설치했으며 저에게 적합합니다. 이미지에 대한

제가

사용

"패턴"{ "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" 
      } 
     }