GraphQL文件上传cURL请求触发JSONDecodeError,寻求问题排查帮助
问题分析与解决方案
核心问题:JSON语法错误
你的operations参数里的JSON存在语法错误:在"saveName": "hello" }之后错误使用了数组闭合符],而这里应该用对象闭合符}。这个语法错误直接导致JSON解析器无法正确解码请求内容,抛出了json.decoder.JSONDecodeError。
修正后的cURL命令
将错误的]替换为},修正后的完整命令如下:
curl http://localhost:3001/graphql/ -F operations='{ "query": "mutation ConvertDocToPDF($input: ConvertWordDocToPDFInputType!){ convertDocToPDF(input: $input){ success } } ", "variables": { "input" : { "file": null, "saveName": "hello" } } }' -F map='{ "0": ["variables.input.file"] }' -F 0=@README.md
额外注意事项
- 确保你的Flask GraphQL服务器已配置支持
multipart/form-data格式请求,多数GraphQL库需要额外启用文件上传扩展(比如Ariadne的upload_scalar、Graphene的FileUpload)才能处理这类请求。 - 确认GraphQL schema中
ConvertWordDocToPDFInputType的file字段类型为上传标量(如Upload),否则服务器无法识别文件参数。
内容的提问来源于stack exchange,提问作者crispengari
相关产品推荐
相关产品推荐

