Postalzc -
Postalzc -

Reputation: 21

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

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

Upvotes: 2

Views: 2386

Answers (1)

vp124
vp124

Reputation: 435

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']
    ...

Upvotes: 1

Related Questions