[英]Sending (nested) json object with file using Postman
With Postman, I can attach files in requests with form-data, I can also send nested JSON object in raw format, but how can I do both: sending nested-structure data with file, eg:使用 Postman,我可以在请求中附加带有表单数据的文件,我还可以发送原始格式的嵌套 JSON 对象,但我怎样才能做到这两点:发送带有文件的嵌套结构数据,例如:
"data": {
"normal_fields": {
"field1": "value1",
"field2": "value2"
},
"image_file": <file>
}
Try setting values like below and choose file to upload.尝试设置如下值并选择要上传的文件。
It didn't worked for me like that.它对我不起作用。 For me only worked this way:
对我来说,只有这样工作:
property[nested_field1]
property[nested_field2]
or arrays with objects:或带有对象的数组:
array[0][nested_field1]
array[0][nested_field2]
array[1][nested_field1]
array[1][nested_field2]
In case if someone needs to send an array of files, this syntax worked for me:如果有人需要发送一组文件,这种语法对我有用:
<field_name>[0]
<field_name>[1]
...
<field_name>[n]
But if you are sending files as an array of nested objects: Ie但是,如果您将文件作为嵌套对象数组发送:即
{
"files": [
{
"file": <file>
},
{
"file": <file>
},
]
}
Then try this:然后试试这个:
files[0]file
files[1]file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.