You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Postman GraphQL文件上传如何配置operations map解决file为null问题

错误点说明

  • map字段的变量映射路径错误:你需要绑定的file字段嵌套在variables.my_data数组的第0个元素内,原有配置的variables.file是根层级路径,无法匹配到正确的参数位置,导致服务端无法关联上传的文件,最终拿到null值。
  • mutation变量类型与schema定义不匹配:schema中createMutation接口的my_data参数为单个input_data类型,但你在operations中定义的$my_data是[input_data]数组类型,若服务端开启严格类型校验会直接返回报错。

调整方案

如果你需要上传数组格式的my_data

  1. 保持现有operations内容不变,将map字段的配置替换为:
{ "0" : ["variables.my_data.0.file"] }

该路径会准确指向数组第0项的file字段,完成文件和变量的绑定。

如果你只需要上传单个my_data对象

  1. 先修正operations的内容:
{
  "query": "mutation CreateMutation($my_id: ID! , $my_data: input_data) { createMutation(my_id: $my_id, my_data : $my_data) { some_key }}",
  "variables": {
    "my_id": "some-string-id",
    "my_data": {
      "some_key": 123,
      "file" : null
    }
  }
}
  1. 同步修改map字段的配置:
{ "0" : ["variables.my_data.file"] }

最终校验规则

保持Postman的Body选择form-data格式:

  • operations和map两个字段的类型设置为Text
  • 编号为0的字段类型设置为File,选择本地的file_from_local.png即可正常上传

内容的提问来源于stack exchange,提问作者Sid Anand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 10:06:01