flask-restplus icon indicating copy to clipboard operation
flask-restplus copied to clipboard

Uploading multiple files with swagger UI not working

Open alvarolopez opened this issue 6 years ago • 4 comments

I have an issue uploading several files through the Swagger UI. I have defined the following argument parser for uploading several files:

data_parser = api.parser()
data_parser.add_argument('data',
                         type=werkzeug.FileStorage,                            
                         location="files",                                     
                         dest='files',                                         
                         required=False,                                       
                         action="append")

And this works fine with the following curl request:

curl -X POST "http://0.0.0.0:5000/test" \
     -H  "accept: application/json" \
     -H  "Content-Type: multipart/form-data" \
     -F "data=@test1"  -F "data=@test2"

As I am getting the following in my arguments (once I have parsed them):

{"files": [<FileStorage: u'test1' ('application/octet-stream')>, <FileStorage: u'test2' ('application/octet-stream')>]}

However, if I use the swagger UI, it seems that the curl request it is doing is:

curl -X POST "http://127.0.0.1:5000/test" \
     -H  "accept: application/json" \
     -H  "Content-Type: application/x-www-form-urlencoded" \
     -d "data=%5Bobject%20File%5D&data=%5Bobject%20File%5D"

Therefore my arguments are empty:

{"files": None}

I am using flask-restplus version 0.11.0.

alvarolopez avatar Jul 11 '18 10:07 alvarolopez

getting the same issue here, any workaround?

miguelvr avatar Feb 28 '19 14:02 miguelvr

Same here - uploading files is not working. UI show file selection dialog, but "Execute" action does not pushes file (POST) to the endpoint. Arriving request has no files in it.

E.g. this service declaration DOES generate the file input in Swagger UI, but posting file to it from UI does not work (curl -F file=@filename still works file)

  /service:
    post:
      operationId: service.service
      parameters:
        - name: file
          in: formData
          required: false
          schema:
            type: file
            format: binary

0anton avatar Jul 25 '19 09:07 0anton

Same issue here. A workaround would be nice. It's worth noting that removing action="append" (which, of course, causes the UI to only upload one file), works as expected.

brahmpowell avatar May 27 '20 14:05 brahmpowell

Encountering the same issue intermittently. Something related to our project launch configuration but I cannot figure out what is that specifically.

Update: [19/2/21] Upgrading to latest v6 package has resolved our issues. Still not certain why it worked sometimes in the past and failed at others.

tanveerbadar avatar Feb 15 '21 14:02 tanveerbadar