graphene-file-upload icon indicating copy to clipboard operation
graphene-file-upload copied to clipboard

Error: django.utils.datastructures.MultiValueDictKeyError: '1'

Open fabian-ws opened this issue 4 years ago • 9 comments

Hello Imcgartland,

I've been busy all day with trying to upload an image to django by react-native. After reading a lot I landed at graphene-file-upload. Unfortunately, I do not get it to work and I hope you can help.

I get the following error message:

Request Method: POST
http://192.168.2.22:8000/graphql/
2.2.6
MultiValueDictKeyError
'1'
/backend/env/lib/python3.7/site-packages/django/utils/datastructures.py in getitem, line 80
/backend/env/bin/python
3.7.4
['/backend', '/Applications/PyCharm.app/Contents/helpers/pydev', '//backend', '/Applications/PyCharm.app/Contents/helpers/pycharm_display', '/Applications/PyCharm.app/Contents/helpers/third_party/thriftpy', '/Applications/PyCharm.app/Contents/helpers/pydev', '/Library/Caches/PyCharm2019.2/cythonExtensions', '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/backend/env/lib/python3.7/site-packages', '/Applications/PyCharm.app/Contents/helpers/pycharm_matplotlib_backend']
Fri, 18 Oct 2019 17:17:42 +0000

My request is the following:

accept: */*
authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InVsbG1hbm4uaW5AZ21haWwuY29tIiwiZXhwIjoxNTcwNzg0Njk2LCJvcmlnSWF0IjoxNTcwNzg0Mzk2fQ.JOsSqFIkwRw5lrd6easuWeKYES346qzq9_jFbp8m9Vw
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryyhscsCwqLniB9NlA
Origin: file://

------WebKitFormBoundaryyhscsCwqLniB9NlA
Content-Disposition: form-data; name="operations"

{"operationName":"UploadEventPicture","variables":{"file":null},"query":"mutation UploadEventPicture($file: Upload!) {\n  uploadEventPicture(file: $file) {\n    success\n    __typename\n  }\n}\n"}
------WebKitFormBoundaryyhscsCwqLniB9NlA
Content-Disposition: form-data; name="map"

{"1":["variables.file"]}
------WebKitFormBoundaryyhscsCwqLniB9NlA
Content-Disposition: form-data; name="1"

[object Object]
------WebKitFormBoundaryyhscsCwqLniB9NlA--

On the client-side I´m using 'apollo-upload-client' as described on their page.

I can see in the debugger that the error occurs in this function: (graphene_file_upload/utils.py)

def place_files_in_operations(operations, files_map, files):
    """Replaces None placeholders in operations with file objects in the files
    dictionary, by following the files_map logic as specified within the 'map'
    request parameter in the multipart request spec"""
    path_to_key_iter = (
        (value.split('.'), key)
        for (key, values) in iteritems(files_map)
        for value in values
    )
    # Since add_files_to_operations returns a new dict/list, first define
    # output to be operations itself
    output = operations
    for path, key in path_to_key_iter:
        file_obj = files[key]
        output = add_file_to_operations(output, file_obj, path)
    return output

-> file_obj = files[key]

the files array is empty.

Do you have an idea what I´m doing wrong?

fabian-ws avatar Oct 18 '19 17:10 fabian-ws

Hey @fabull86 can you solve that error?

I'm evaluating this library. I wanted to know if it is stable considering that my application will use a lot of image uploads.

marlonpatrick avatar Jun 12 '20 14:06 marlonpatrick

The same problem

luckyy199213 avatar Nov 24 '20 11:11 luckyy199213

same problem

felixmeziere avatar May 25 '21 17:05 felixmeziere

same problem

avaltat avatar Oct 04 '21 10:10 avaltat

Hey here, any intention to merge the PR to solve this problem?

felixmeziere avatar Oct 15 '21 16:10 felixmeziere

any workarounds for this issue?

Delvio avatar Nov 21 '21 00:11 Delvio

Same here. When would #66 be released?

delegacy avatar Mar 17 '22 12:03 delegacy

Yes guys, I'm on v1.3.0, and it's still throwing same error. When would https://github.com/lmcgartland/graphene-file-upload/pull/66 be released? @delegacy did you find any other way to get around this?

rukna123 avatar Feb 28 '23 02:02 rukna123

def place_files_in_operations(operations, files_map, files):
    """Replaces None placeholders in operations with file objects in the files
    dictionary, by following the files_map logic as specified within the 'map'
    request parameter in the multipart request spec"""
    path_to_key_iter = (
        (value.split('.'), key)
        for (key, values) in iteritems(files_map)
        for value in values
    )
    # Since add_files_to_operations returns a new dict/list, first define
    # output to be operations itself
    output = operations
    for path, key in path_to_key_iter:
        file_obj = files.get(key, None)
        output = add_file_to_operations(output, file_obj, path)
    return output

This solves the problem for me.

Apro2011 avatar Mar 27 '23 05:03 Apro2011