noirbizarre / flask-restplus

Fully featured framework for fast, easy and documented API development with Flask
http://flask-restplus.readthedocs.org
Other
2.73k stars 506 forks source link

Uploading multiple files with swagger UI not working #491

Open alvarolopez opened 6 years ago

alvarolopez commented 6 years ago

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.

miguelvr commented 5 years ago

getting the same issue here, any workaround?

0anton commented 5 years ago

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
brahmpowell commented 4 years ago

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.

tanveerbadar commented 3 years ago

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.