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

Created on 8 Jul 2019  路  10Comments  路  Source: zalando/connexion

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

Most helpful comment

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.

All 10 comments

cc @dtkav @hjacobs

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

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

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?

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.

status?

@dfeinzeig it looks like its being worked on here if you want to check it out :wink: : https://github.com/zalando/connexion/pull/1222

@kornicameister, I know it's been a while, but would you mind checking if either master or my PR #1222 fixes your issue? Do you still have what's needed to check it?

Thanks

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.

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

Was this page helpful?
0 / 5 - 0 ratings