我正在使用 Swagger 编辑器构建发布请求以上传文件。我的 swagger json 文件定义如下。
swagger: '2.0'
info:
version: 0.0.0
title: '<enter your title>'
host: 'localhost:11235'
paths:
/form/upload:
post:
description: |
Post files.
consumes:
- multipart/form-data
produces:
- application/octet-stream
parameters:
- name: file
in: formData
description: upload file
required: true
type: file
- name: text
description: additional info
in: formData
type: string
responses:
'200':
description: Successful response
schema:
type: file
然后在编辑器的右侧。我单击尝试此操作。我选择一个文件。构造的请求如下所示。
POST http://localhost:11235/form/upload HTTP/1.1
....
Content-Length: 40
Content-Type: multipart/form-data
file: C:\fakepath\swagger.json
text: 123
文件内容不会在请求中传输。只有文件名写入请求。这是因为 swagger 编辑器不支持文件上传还是我的 swagger json 错误?有人可以帮我解决这个问题吗?谢谢。