connexion: Multiple files upload (mutlipart/form-data) is ignored for Flask

Description

Consider following endpoint definition:

  /test-formData-file-upload:
    post:
      summary: 'Test formData with file type, for file upload'
      operationId: fakeapi.hello.test_formdata_file_upload
      responses:
        '200':
          description: OK
      requestBody:
        content:
          multipart/form-data:
            schema:
              x-body-name: formData
              type: object
              properties:
                formData:
                  type: array
                  items:
                    type: string
                    format: binary
              required:
                - formData

What we are doing in here is uploading multiple files from the same mulipart field. That gets correctly pulled from flask_request but ignored later in connexion.operations.abstract.AbstractOperation#_get_file_arguments

Expected behaviour

Request to Flask-based application with multiple files is correctly processed and we get multiple files available inside of handler.

Actual behaviour

Multiple files are ignored, only first is taken into account.

Steps to reproduce

  1. open connexion/tests/fixtures/simple/openapi.yaml
  2. find /test-formData-file-upload definition
  3. Use snippet from above to replace the definition
  4. Go to tests.api.test_parameters.test_formdata_file_upload
  5. Use following code to replace the function
def test_formdata_file_upload(simple_app):
    app_client = simple_app.app.test_client()
    resp = app_client.post('/v1.0/test-formData-file-upload',
                           data={'formData': [(BytesIO(b'file contents'), 'filename1.txt'), (BytesIO(b'file contents'), 'filename2.txt')]})
    assert resp.status_code == 200
    response = json.loads(resp.data.decode('utf-8', 'replace'))
    assert response == {'filename1.txt': 'file contents'}
  1. Observe test to pass, which it should not do.

Additional info:

Output of the commands:

  • python --version -> 3.7.3
  • pip show connexion | grep "^Version\:" -> master branch
  • flask --version -> 1.1.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 15 (9 by maintainers)

Commits related to this issue

Most upvoted comments

You can get the files from connexion.request.files.getlist('formData')

What is the status of this issue? Can we expect to have the possibility to perform multiple files uploads or should we choose another framework? It is indeed related to #987, which seems to be slightly updated though.

I think this is closed by #1000 Please re-open if thereโ€™s something I missed.

https://github.com/zalando/connexion/pull/1000 was reverted in https://github.com/zalando/connexion/pull/1101 because it broke httpaio backend

I think this is being followed in https://github.com/zalando/connexion/pull/987

Kindly bumping ๐Ÿ˜ƒ I could use Flask multipart file upload, perhaps this issue should be reopened?

hey @ddurham2 I do not have any project setup available, that project is long gone.

My only suggestion to actually verify that would be to write extensive test that loads bunch of files, sends them and you are trying to read them, but this is exactly what you have done. I think that if you manage to write really decent test coverage, it ill be proof enough to verify your PR ๐Ÿ˜‰


I have left some suggestions in PR.

Looks like a duplicate of #510. You can see my fork here https://github.com/simondrabble/connexion for a fix.