mongoDBで画像を任意の辞書とともにインポートしたい。辞書には、スキーマを定義する瞬間に私が知ることのできないタイプ、数字、名前の画像タグが用意されていなければなりません。私は成功せず、前夜に辞書を追加しようとしている :python eveで検証されていない辞書を画像とともに追加する
curl -F"attr={\"a\":1}" -F "img_id=2asdasdasd" -F "[email protected]:\path\
1.png;type=image/png" http://127.0.0.1:5000/images
{"_status": "ERR", "_issues": {"attr": "must be of dict type"}, "_error": {"message": "Insertion failure: 1 document(s)
contain(s) error(s)", "code": 422}}
私のスキーマ定義は、以下のようになります。
'schema': {
#Fixed attributes
'original_name': {
'type': 'string',
'minlength': 4,
'maxlength': 1000,
},
'img_id': {
'type': 'string',
'minlength': 4,
'maxlength': 150,
'required': True,
'unique': True,
},
'img_data': {
'type': 'media'
},
#Additional attributes
'attr': {
'type': 'dict'
}
}
は、それがすべてで可能ですか? dictsのスキーマを修正する必要がありますか?
EDIT は、私が最初に画像を追加したいと、それの後に辞書が、PATCHリクエストでエラーが表示されます。
C:\Windows\SysWOW64>curl -X PATCH -i -H "Content-Type: application/json" -d "{\
"img_id\":\"asdasdasd\", \"attr\": {\"a\": 1}}" http://localhost:5000/images/asd
asdasd
HTTP/1.0 405 METHOD NOT ALLOWED
Content-Type: application/json
Content-Length: 106
Server: Eve/0.7.4 Werkzeug/0.9.4 Python/2.7.3
Date: Wed, 28 Jun 2017 22:55:54 GMT
{"_status": "ERR", "_error": {"message": "The method is not allowed for the requested URL.", "code": 405}}
私は、postmanが動作している同様の要求をどのようにしているのかチェックし、 '--data-binary'でcurlを送信すると動作します。私はあなたの画像を一緒に送信しているので、あなたのContent-typeはマルチパートに調整されるべきだと知っています: 'curl 'http:// localhost:5000/images /' -H 'Content-Type:application/json' --data-binary ' {"attr":{"a":1}} "。 – gcw
@gcw:はい、データを-dによって提供しました(あなたのjsonには必須の属性としてimg_idが含まれている必要があります)が、画像は送信できません。私は最初に画像を送信しようとしましたが、-X PATCHを使用してメタインフォームを追加するよりも、失敗しました。 –
PATCHリクエストのエラーは何ですか? – gcw