graphene-file-upload
graphene-file-upload copied to clipboard
Error: django.utils.datastructures.MultiValueDictKeyError: '1'
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?
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.
The same problem
same problem
same problem
Hey here, any intention to merge the PR to solve this problem?
any workarounds for this issue?
Same here. When would #66 be released?
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?
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.