I am using Swagger editor to build a post request to upload a file. My swagger json file is defined as follows.
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
Then on the right side of the editor. I click the Try this operation. I select a file. The constructed request looks like this.
POST http://localhost:11235/form/upload HTTP/1.1
....
Content-Length: 40
Content-Type: multipart/form-data
file: C:\fakepath\swagger.json
text: 123
The file content is not transferred in the request. Only the file name is written into the request. Is this because swagger editor does not support file upload or my swagger json is wrong? Could anyone kindly help me with this? Thanks.
There is still an open issue for swagger-editor: https://github.com/swagger-api/swagger-editor/issues/599
as reported it has been fixed in swagger-api: https://github.com/swagger-api/swagger-ui/issues/838
Use swagger-ui for file uploading, it is working:
- in: formData
name: document
description: Documento Fiscal
required: true
type: file