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" 
      } 
     } 
相關問題