2

How to document HTTP POST/PUT data-binary upload in flask restplus swagger?

flask plus swagger

I can simply use cURL command below to hit the service, but i not sure how to document it in swagger. Thanks

url -v -X PUT -H 'Accept: application/json' -H 'Accept: application/json' -H 'Authorization: {auth}' --data-binary "@data.zip"  http://localhost:18090/api?n=data1
sorak
  • 2,607
  • 2
  • 16
  • 24
Postalzc -
  • 21
  • 2

1 Answers1

1

This is what you can do in swagger to document a file upload of any type:

from werkzeug.datastructures import FileStorage
parser = api.parser()
parser.add_argument('file', type=FileStorage, location='files', required=True)

@api.doc(id='upload', description='Upload file')
@api.expect(parser, validate=True)
def post(self):
    file = request.files['file']
    ...
vp124
  • 317
  • 1
  • 4
  • 1
    the code above will generate multipart-form data which is the problem i facing. In cURL it look like below ```curl -i -X POST -H "Content-Type: multipart/form-data" -F "file=@xxxx" http://localhost:18090/api?n=data1 ``` – Postalzc - Mar 05 '18 at 02:56