Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File uploading with aiohttp (status 500) #975

Closed
fr33mang opened this issue Jun 14, 2019 · 4 comments
Closed

File uploading with aiohttp (status 500) #975

fr33mang opened this issue Jun 14, 2019 · 4 comments

Comments

@fr33mang
Copy link

Description

Connexion return 500 error.

My swagger scheme:

requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                fileName:
                  type: string
                  format: binary

Handler:

async def create_task(self, fileName, **request):
        print(fileName)

Html form:

<form method="post" enctype="multipart/form-data" multipart action="">
    <label for="fileName">Choose file to upload</label>
    <input type="file" id="fileName" name="fileName">
    <button>Submit</button>
</form>

Expected behaviour

FileField(name='fileName', filename='script.sql', file=<_io.BufferedRandom name=12>, content_type='application/octet-stream', headers=<CIMultiDictProxy('Content-Disposition': 'form-data; name="fileName"; filename="script.sql"', 'Content-Type': 'application/octet-stream')>)

Actual behaviour

  File "/lib64/python3.6/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/lib64/python3.6/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "lib64/python3.6/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/lib64/python3.6/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/lib64/python3.6/site-packages/connexion/apis/aiohttp_api.py", line 32, in oauth_problem_middleware
    response = yield from handler(request)
  File "/lib64/python3.6/site-packages/connexion/decorators/coroutine_wrappers.py", line 21, in wrapper
    connexion_response = function(connexion_request)
  File "/lib64/python3.6/site-packages/connexion/decorators/uri_parsing.py", line 143, in wrapper
    response = function(request)
  File "/lib64/python3.6/site-packages/connexion/decorators/validation.py", line 147, in wrapper
    data.update(dict.fromkeys(request.files, ''))  # validator expects string..
AttributeError: 'bytes' object has no attribute 'update'```

### Additional info:

This problem was solved with patching aiohttp_api.AioHttpApi.get_request method.

-Python 3.7.2
-Version: 2.2.0
fr33mang pushed a commit to fr33mang/connexion that referenced this issue Jun 14, 2019
fr33mang pushed a commit to fr33mang/connexion that referenced this issue Jun 14, 2019
fr33mang pushed a commit to fr33mang/connexion that referenced this issue Jun 14, 2019
fr33mang pushed a commit to fr33mang/connexion that referenced this issue Jun 14, 2019
kornicameister pushed a commit to kornicameister/connexion that referenced this issue Jul 5, 2019
changes:

- different handling for multipart and non-multipart requests
- tests confirming the behavior
- minor list to typle changes for collection that ought to be immutable

Fixes spec-first#975
kornicameister pushed a commit to kornicameister/connexion that referenced this issue Jul 9, 2019
changes:

- different handling for multipart and non-multipart requests
- tests confirming the behavior
- minor list to typle changes for collection that ought to be immutable

Fixes spec-first#975
kornicameister pushed a commit to kornicameister/connexion that referenced this issue Jul 9, 2019
changes:

- different handling for multipart and non-multipart requests
- tests confirming the behavior
- minor list to typle changes for collection that ought to be immutable

Fixes spec-first#975
@daxartio
Copy link

Ping. I need solved for the problem. What is status the issue?

@fr33mang
Copy link
Author

Ping. I need solved for the problem. What is status the issue?

@kornicameister create new PR.
But it doesn't merged yet.
I use monkeypatch from this PR :)

ddurham2 added a commit to ddurham2/connexion that referenced this issue Apr 22, 2020
@Acromonkey
Copy link

Is there already a solution on that? I have the problem that I definitely need to upload files to the server and this bug seems to still persist.

RichardBruskiewich pushed a commit to STARInformatics/connexion that referenced this issue Mar 11, 2021
RobbeSneyders pushed a commit that referenced this issue Feb 18, 2022
* Added unit tests to demonstrate the problems of #975
    - Taken mostly from existing PR: #987

* now splitting out multipart POSTs into files[] and form[], handling duplicate keys as the rest of connexion expects
    - Based parly on existing PR: #987

* rewrote how operations/openapi.py::_get_body_argument() works to better build the arguments[] list according to what the spec says and what the handler accepts.  This fixes a bug when requests contain mixed files and form values and the handler is expecting variable names matching the request property names.

* Adding unit tests to improve code converage test

* post merge fixes - using 'async' keyword now in new unit test file

* unit test improvements -- now testing the contents of the files we upload too

* making some code a bit clearer regarding duplicate names of file submissions

* fixing up unit tests since merging main

* fixing isort-check-tests and flake8

* clarified a comment

* comment correction

* after discussions with maintainer, reverted _get_body_argument back to the original where it does not attempt to break out the body into individual arguments for the handler.  But left in changes that make the normal behavior of not passing a body argument to a handler without one more consistent when the body itself is empty or not an object type.

* fixing unit tests after after reverting _get_body_argument behavior
@RobbeSneyders
Copy link
Member

Should be fixed by #1222

vbxx3 pushed a commit to Savannah-Group/connexion that referenced this issue Apr 9, 2022
* Added unit tests to demonstrate the problems of spec-first#975
    - Taken mostly from existing PR: spec-first#987

* now splitting out multipart POSTs into files[] and form[], handling duplicate keys as the rest of connexion expects
    - Based parly on existing PR: spec-first#987

* rewrote how operations/openapi.py::_get_body_argument() works to better build the arguments[] list according to what the spec says and what the handler accepts.  This fixes a bug when requests contain mixed files and form values and the handler is expecting variable names matching the request property names.

* Adding unit tests to improve code converage test

* post merge fixes - using 'async' keyword now in new unit test file

* unit test improvements -- now testing the contents of the files we upload too

* making some code a bit clearer regarding duplicate names of file submissions

* fixing up unit tests since merging main

* fixing isort-check-tests and flake8

* clarified a comment

* comment correction

* after discussions with maintainer, reverted _get_body_argument back to the original where it does not attempt to break out the body into individual arguments for the handler.  But left in changes that make the normal behavior of not passing a body argument to a handler without one more consistent when the body itself is empty or not an object type.

* fixing unit tests after after reverting _get_body_argument behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants